Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Can any one please tell me how do I write a select query that gives me all the dates present in a specified month. Is there any table in sql server 2008(as I am currently using this one) where I can query?
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2011-08-02 : 17:42:45
You can do it using a numbers table (or by constructing one on the fly as shown below):
DECLARE @startDate DATETIME;SET @startDate = '20110801';;WITH N(n) AS(SELECT 0 UNION ALL SELECT n+1 FROM N WHERE n < 30)SELECT DATEADD(dd,n,@startDate)FROM NWHERE MONTH(DATEADD(dd,n,@startDate)) = MONTH(@startDate);