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
 date column

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2008-03-24 : 13:37:33
how do i get a column showing the next 30 days?

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-03-24 : 13:48:26
select Convert(varchar(10), MyDate, 101) from
(
select getdate() + 01 as MyDate union all
select getdate() + 02 as MyDate union all
select getdate() + 03 as MyDate union all
select getdate() + 04 as MyDate union all
select getdate() + 05 as MyDate union all
select getdate() + 06 as MyDate union all
select getdate() + 07 as MyDate union all
select getdate() + 08 as MyDate union all
select getdate() + 09 as MyDate union all
select getdate() + 10 as MyDate union all
select getdate() + 11 as MyDate union all
select getdate() + 12 as MyDate union all
select getdate() + 13 as MyDate union all
select getdate() + 14 as MyDate union all
select getdate() + 15 as MyDate union all
select getdate() + 16 as MyDate union all
select getdate() + 17 as MyDate union all
select getdate() + 18 as MyDate union all
select getdate() + 19 as MyDate union all
select getdate() + 20 as MyDate union all
select getdate() + 21 as MyDate union all
select getdate() + 22 as MyDate union all
select getdate() + 23 as MyDate union all
select getdate() + 24 as MyDate union all
select getdate() + 25 as MyDate union all
select getdate() + 26 as MyDate union all
select getdate() + 27 as MyDate union all
select getdate() + 28 as MyDate union all
select getdate() + 29 as MyDate union all
select getdate() + 30 as MyDate union all
select getdate() + 31 as MyDate
) a


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-24 : 14:03:02
or:-
SELECT DATEADD(d,number,GETDATE())
FROM master..spt_values
WHERE number BETWEEN 1 AND 31
AND type='p'
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-03-24 : 14:25:53
Use the date table function from the link below.

Date Table Function F_TABLE_DATE
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519

declare @start_date	datetime
declare @end_date datetime
select @start_date = getdate()+1
select @end_date = @start_date+30

select
*
from
dbo.F_TABLE_DATE ( @start_date, @end_date )



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -