動的 SQL の使用、SQL Server 2005+ (@table_name および @numCrossJoins はストアド プロシージャ パラメータ):
DECLARE @upperLimit INT
SET @upperLimit = 1
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'SELECT * FROM '+ @table_name +' '
BEGIN
WHILE (upperLimit <= @numCrossJoins)
BEGIN
SET @SQL = @SQL + 'CROSS JOIN '+ QUOTENAME(@table_name) +' '
SET @upperLimit = @upperLimit + 1
END
EXEC sp_executesql @SQL
END