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 |
ahaile
Starting Member
25 Posts |
Posted - 2010-08-11 : 15:54:45
|
Here is what I am trying to do; I have declared seven variables for dates, based on a given date I need to determine the last 7 dates.Here is where I declare my date variables@metric_pd1 datetime,@metric_pd2 datetime,@metric_pd3 datetime,@metric_pd4 datetime,@metric_pd5 datetime,@metric_pd6 datetime,@metric_pd7datetime'set @metric_pd1 = @EnterEndDate -- 'Example '20100109' for my end date.Next I need to set my second variable based on the entry for @metric_pd1.set @metric_pd2 = @metric_pd1 -1 -- Expected Value '20100108'Any direction or suggestion greatly appreciated. |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-11 : 16:00:25
|
[code]declare @metric_pd1 datetimedeclare @metric_pd2 datetimedeclare @metric_pd3 datetimedeclare @metric_pd4 datetimedeclare @metric_pd5 datetimedeclare @metric_pd6 datetimedeclare @metric_pd7 datetimedeclare @Enddate datetimeset @Enddate = '20100109'select @metric_pd1 = @Enddate,@metric_pd2 = dateadd(day,-1,@Enddate),@metric_pd3 = dateadd(day,-2,@Enddate),@metric_pd3 = dateadd(day,-3,@Enddate)select @metric_pd1,@metric_pd2,@metric_pd3[/code]But why do you need 7 variables to store all of them. Can't you just calculate from @Enddate |
 |
|
ahaile
Starting Member
25 Posts |
Posted - 2010-08-11 : 16:18:07
|
Thanks Vijay. The SQL script i am working on has been setup to run this way. But I may consider that, if this does not workout. |
 |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-11 : 16:53:33
|
Ok. But my gut feel is you can do away with all 7 variables and caluclate them wherever necessary. Let us know how it went. |
 |
|
|
|
|
|
|