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
 General SQL Server Forums
 New to SQL Server Programming
 Last Month Of year

Author  Topic 

Chamark
Starting Member

28 Posts

Posted - 2010-08-24 : 13:32:44
I'm trying to create a query that will provide the last month of the year based on a month provided. So if 06/01/2010 is provided how would I get 12/01/2010 to use in a query? Probably easy, I just don't see it. Any help is appreciated.

DECLARE @report_date
Set @report_date = '06/01/2010'
Select col
FROM DB
Where last_month_of_Year = ???

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-24 : 13:37:40
What data type is last_month_of_year?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Chamark
Starting Member

28 Posts

Posted - 2010-08-24 : 14:04:29
Datetime
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-24 : 14:12:06
quote:
Originally posted by Chamark

Datetime


Maybe this...
DECLARE @report_date datetime
Set @report_date = '20100121'

Select col
FROM DB
Where last_month_of_Year =
dateadd(mm,12-month(@report_date),@report_date)
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-08-24 : 14:19:09
[code]declare @report_date datetime
set @report_date = '06/01/2010'

select Dec01ofSameYear = dateadd(yy,datediff(yy,-1,@report_date),-31)[/code]


Results:
[code]Dec01ofSameYear
-----------------------
2010-12-01 00:00:00.000
[/code]

CODO ERGO SUM
Go to Top of Page

Chamark
Starting Member

28 Posts

Posted - 2010-08-24 : 14:28:18
Thank you so much I got it to work
Go to Top of Page
   

- Advertisement -