Tuesday, December 1, 2009

Generate a sequence of numbers in TSQL

Sometimes you need a quick way to generate a sequence of numbers. The recursive query functionality that was introduced in SQL Server 2005 makes this really easy.

WITH Numbers (val) AS 
(
SELECT 1 as val
UNION ALL
SELECT 1 + val FROM Numbers WHERE val < 100
)

No comments:

Post a Comment