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 |
|
diggydee
Starting Member
5 Posts |
Posted - 2009-10-02 : 11:13:34
|
| I have a job running 1st of every month to get last month data, I used this as date condition dateadd(m,datediff(m,0,getdate()-1),0) if I run today I have to change that -1 to -2 ….is that any date function available so that when ever I ran I have to get last month dataAny Hits are appriciatedThanksDiggy |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-02 : 11:16:16
|
yup just useSELECT columns... FROM YourTable WHERE datefield>=DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0) AND datefield<DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-02 : 11:16:49
|
to get last month date rangeusewhere datecol >= dateadd(month, datediff(month, 0, getdate()) - 1, 0) -- 1st of last monthand datecol < dateadd(month, datediff(month, 0, getdate()), 0) -- 1st of current month KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-02 : 11:17:26
|
too slow KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-02 : 11:19:26
|
quote: Originally posted by khtan
too slow KH[spoiler]Time is always against us[/spoiler]
Nope just a matter of 33 sec |
 |
|
|
diggydee
Starting Member
5 Posts |
Posted - 2009-10-02 : 11:29:18
|
| Thanks a lot guys |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-02 : 11:31:36
|
welcome |
 |
|
|
|
|
|
|
|