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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 [Resolved] Monthly buckets for current year

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2010-08-03 : 08:59:49
For any current year I need to set up 12 buckets (by each month) with a from date and to date for each month. How can I easily do that? Thank you.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-08-03 : 09:15:09
SELECT DATEADD(month,spt.number,'20100101') as FromDate,DATEADD(month,spt.number+1,'20100101') as ToDate
FROM master..spt_values spt
WHERE spt.number < 12 and spt.type = 'P'

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -