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 |
|
MBeal
Posting Yak Master
110 Posts |
Posted - 2006-02-13 : 15:22:53
|
| Can you think of a quick way to return the first day of the month for last month?In my data, there is a received date which is always the first day of the month (2006-01-01 00:00:00). Max(ReceivedDate) will return the maximum date in this column however I want to grab the next to maximum or perhaps it would be better said "Last Month's Date". So if this month it shows 2006-01-01 00:00:00 then I want it to return 2005-12-01 00:00:00.Do you have any quick ways to do this without a long drown out case statement using dateparts and date add's?MBeal |
|
|
Tapalotapus
Starting Member
22 Posts |
Posted - 2006-02-13 : 15:32:42
|
| select dateadd(mm,-1,'2005-12-01 00:00:00') |
 |
|
|
MBeal
Posting Yak Master
110 Posts |
Posted - 2006-02-13 : 15:35:19
|
| The answer is usually that simple. I couldn't see the forest for the trees and I was making it far too difficult. ThanksMBeal |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-14 : 01:51:47
|
| >>select dateadd(mm,-1,'2005-12-01 00:00:00')Just for clarity, use month instead of mmselect dateadd(month,-1,'2005-12-01 00:00:00')MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|