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 |
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-01-18 : 12:28:13
|
Hi, i am using this code:-Declare @dt1 datetime, @dt2 datetime, @dt3 datetime, @dt4 datetimeset @dt1 = dateadd(d,-7,GETDATE())set @dt2 = GETDATE()set @dt3 = dateadd(d,-8,GETDATE())set @dt4 = dateadd(d,-1,GETDATE())I am using all the 4 dates in my sql queries.I want same dates but last year..For example...if @dt1 is 14-12-2011the new @dt5 should be 14-12-2010I need 1 year old dates beacuse I am comparing sales from last year..Regards,SushantDBAVirgin Islands(U.K) |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-01-18 : 12:32:20
|
Maybe: SET @dt5 = DATEADD(YEAR, -1, @dt1) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-18 : 13:35:05
|
quote: Originally posted by X002548 do you really THINK we should be helping a DBA who lives and works in the Virgin Islands...I mean..I'm in Newark for god's sake;-)
Be thankful for what you have, Brett. It's the middle of January and still hasn't snowed yet. Sort of like Virgin Islands. |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-01-18 : 13:46:09
|
quote: Originally posted by Lamprey Maybe: SET @dt5 = DATEADD(YEAR, -1, @dt1)
thanks, it workedRegards,SushantDBAVirgin Islands(U.K) |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-01-18 : 13:46:57
|
quote: Originally posted by X002548 do you really THINK we should be helping a DBA who lives and works in the Virgin Islands...I mean..I'm in Newark for god's sake;-)Brett8-)
i didn't get u Brett :(Regards,SushantDBAVirgin Islands(U.K) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-01-18 : 14:16:58
|
quote: Originally posted by X002548 Hey..I like Snow...in the Mountainshttp://www.weather.com/weather/tenday/Newark+NJ+USNJ0355I guess I can't complain..after all it's Januaryhttp://www.weather.com/weather/tenday/18.335765,-64.896335Doesn't look like Beach weatherBrett8-)
I don't like snow thatsy I came from chicago to British Virgin Islands (BVI)...btw the link u gave is of Saint thomas which is USVI, not BVI..Here in BVI, its beach weather, infact its hotter than beach weather...Many toursits come here this time of the year to enjoy beach.Thanks.Regards,SushantDBAVirgin Islands(U.K) |
 |
|
|
|
|
|
|