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.
| 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_dateSet @report_date = '06/01/2010'Select colFROM DBWhere last_month_of_Year = ??? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Chamark
Starting Member
28 Posts |
Posted - 2010-08-24 : 14:04:29
|
| Datetime |
 |
|
|
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 datetimeSet @report_date = '20100121'Select colFROM DBWhere last_month_of_Year = dateadd(mm,12-month(@report_date),@report_date) |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-08-24 : 14:19:09
|
| [code]declare @report_date datetimeset @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 |
 |
|
|
Chamark
Starting Member
28 Posts |
Posted - 2010-08-24 : 14:28:18
|
| Thank you so much I got it to work |
 |
|
|
|
|
|