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)
 Last Day of Every month

Author  Topic 

phanicrn
Starting Member

42 Posts

Posted - 2010-10-13 : 16:31:29
how to write syntax for finding last day of every month

Phani

TimSman
Posting Yak Master

127 Posts

Posted - 2010-10-13 : 17:06:52
Try this:

http://www.lmgtfy.com/?q=find+last+day+of+month+t-sql
Go to Top of Page

phanicrn
Starting Member

42 Posts

Posted - 2010-10-13 : 17:14:04
I cant open this link..
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-10-13 : 17:49:51
All months? This will get you all in the range from 1900-01-31 to 9999-11-30:
;WITH 
Tens (N) AS (SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9),
Thousands(N) AS (SELECT t1.N FROM Tens t1 CROSS JOIN Tens t2 CROSS JOIN Tens t3),
Millions (N) AS (SELECT t1.N FROM Thousands t1 CROSS JOIN Thousands t2),
Tally (N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM Millions)

select dateadd(month, N, 0) - 1
from Tally
where N > 0 AND N <= 97199
Go to Top of Page
   

- Advertisement -