Create Number Table in SQL Server

Posted by Neerajprasadsharma under Sql Server category on | Points: 40 | Views : 1477
This is the amazing Number table which is very effective in solving challenging problems in SQL Server.
I will use this in my series to build the base tables, so here is the code below:

Create table Numbers (N Int Primary Key Clustered)

insert into Numbers
TOP 500000 Convert ( Varchar (50) , Row_Number () Over (Order By S1.number ) )

FROM master.dbo.spt_values s1
CROSS JOIN master.dbo.spt_values s2

Comments or Responses

Login to post response