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)
 select month-end dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 03/04/2013 :  05:20:24  Show Profile  Reply with Quote
Hi,
1- I pass the month-end date such as '31 march 2013',
2- The stored proc works out the first and lastdate i.e.
@FirstDate='01 jan 2013'
@LastDate = '31 march 2013'

3- Then my select query does : select myDate from tblDates where myDate between @FirstDate and @LastDate

4- It returns many dates ...

5- I would like to get back the month-end dates i.e.
31 jan 2013
28 feb 2013
31 march 2013

6- How is this done please?

Thank you

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/04/2013 :  06:05:33  Show Profile  Reply with Quote

SELECT DISTINCT DATEADD(dd,-1,DATEADD(mm,DATEDIFF(mm,0,myDate),0))
from tblDates 
where myDate >= @FirstDate 
and myDate < DATEADD(dd,1,@LastDate)


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

Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 03/04/2013 :  08:56:06  Show Profile  Reply with Quote
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/04/2013 :  23:42:19  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.09 seconds. Powered By: Snitz Forums 2000