[ACCEPTED]-Create Temp Table with Range of Numbers-sql-server-2008

Accepted answer
Score: 13
WITH    q AS
        (
        SELECT  startId, endId
        FROM    ranges
        UNION ALL
        SELECT  startId + 1, endId
        FROM    q
        WHERE   startId < endId
        )
SELECT  startId
FROM    q
OPTION  (MAXRECURSION 0)

0

Score: 6

In MSSQL, you can also use select from any 3 arbitrary large table, syscolumns would 2 be an example. If there are not enough rows 1 - you can do a cross join:

SELECT        TOP 10000
ROW_NUMBER() OVER (ORDER BY c1.id)
FROM          syscolumns AS c1
CROSS JOIN    syscolumns AS c2

More Related questions