SQLUSA

Microsoft SQL Server 2005 Best Practices

How to generate a date sequence with ROW_NUMBER?

 

Execute the following script in Query Editor to generates the next 1000 dates starting today:


use AdventureWorks

select top 1000 [Date] = dateadd(day, ROW_NUMBER()
over(order by c1.name, c2.name), convert(char(10),getdate()-1,110))
from sys.columns c1
cross join sys.columns c2

 

SQLUSA - The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page