Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1433 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
52326 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

1433 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
52326 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  
 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.14 seconds. Powered By: Snitz Forums 2000