SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 month-end dates in quarter
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 01/28/2013 :  05:57:42  Show Profile  Reply with Quote
Hi,

If I pass in a quarter-end i.e. 30 sep 2012, then I would like to get the month-end dates of each month in that quarter.

So for this example, it should return:
31 July 2012
31 Aug 2012
30 sep 2012

How is this done in sql please?
Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/28/2013 :  06:14:22  Show Profile  Reply with Quote

DECLARE @date datetime

SET @date='20120930'

SELECT DATEADD(mm,N,DATEADD(qq,DATEDIFF(qq,0,@date),0))-1
FROM (SELECT 1 AS N
UNION ALL
SELECT 2
UNION ALL
SELECT 3
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 01/28/2013 :  06:26:54  Show Profile  Reply with Quote
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/28/2013 :  06:34:00  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000