Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a report that I need to run on 2 different date ranges.Both report's data is 2 days behind today's date.so...WHERE reportdate between dateadd('d',date(),-2) and dateadd('d',date(),-2)OR SOMETHING LIKE THAT, NO BIGGIE HEREThe 2nd report is a month to date report. This is the 1 I can't figure out.WHERE reportdate between (the first day of this month) and dateadd('d',date(),-2)So that would look likeWHERE reportdate between 1/1/2007 and 1/21/2007My problem is, if today is the 1st day of the month... how can I get my critiera to NOT do thisWHERE reportdaye between 2/1/2007 and 1/30/2007Any help would be greatly appriciated!
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2007-01-23 : 10:12:25
this ?
where reportdaye between dateadd(month, datediff(month, 0, dateadd(day, -2, getdate())), 0) and dateadd(day, -2, getdate())
KH
tmaiden
Yak Posting Veteran
86 Posts
Posted - 2007-01-23 : 10:28:47
That should work. I am actually writting this for Crystal Reports but I knew the logic would be the same.Crystal SyntaxWHERE reportdate between date(year(currentdate-2),month(currentdate-2),1) and currentdate-2Thanks