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 |
qman
Constraint Violating Yak Guru
442 Posts |
Posted - 2010-10-13 : 12:54:00
|
Could someone help me out with the following SQL Logic?Specifically, I am trying to revreive records where a date value is >= first day of the previous monthANDa date value is < first day of current monthAny ideas?select * from tablenamewhereTRANSACTION_CREATE_TS >= first day of previous month andTRANSACTION_CREATE_TS < first day of current month |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-13 : 13:13:32
|
[code]TRANSACTION_CREATE_TS >= DateAdd(month, DateDiff(month, 0, getdate())-1, 0)andTRANSACTION_CREATE_TS < DateAdd(month, DateDiff(month, 0, getdate()), 0)[/code]or[code]TRANSACTION_CREATE_TS BETWEEN DateAdd(month, DateDiff(month, 0, getdate())-1, 0) AND DateAdd(month, DateDiff(month, 0, getdate()), 0)-1[/code] |
 |
|
qman
Constraint Violating Yak Guru
442 Posts |
Posted - 2010-10-13 : 13:20:22
|
Sweet, you the man Russell! |
 |
|
|
|
|
|
|