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 2008 Forums
 Transact-SQL (2008)
 select month-end dates

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-03-04 : 05:20:24
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

52326 Posts

Posted - 2013-03-04 : 06:05:33
[code]
SELECT DISTINCT DATEADD(dd,-1,DATEADD(mm,DATEDIFF(mm,0,myDate),0))
from tblDates
where myDate >= @FirstDate
and myDate < DATEADD(dd,1,@LastDate)
[/code]

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

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-03-04 : 08:56:06
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 23:42:19
welcome

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

Go to Top of Page
   

- Advertisement -