Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 create range of numbers

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2012-01-23 : 15:44:24
How can I create a table with a numbers listed from 40000 49999?

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-23 : 17:05:07
http://weblogs.sqlteam.com/brettk/archive/2010/10/29/set-based-number-table-create-hack.aspx


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-23 : 17:20:51
Here is an in-line tally table that you can adjust to suit your needs:
SET STATISTICS TIME ON;
DECLARE @N INT

;WITH
Tens (N) AS (SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9),
Thousands(N) AS (SELECT t1.N FROM Tens t1 CROSS JOIN Tens t2 CROSS JOIN Tens t3),
Millions (N) AS (SELECT t1.N FROM Thousands t1 CROSS JOIN Thousands t2),
Tally (N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM Millions)

SELECT TOP (1000000)
@N = N
FROM Tally;
Go to Top of Page
   

- Advertisement -