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 |
steve_r18
Yak Posting Veteran
59 Posts |
Posted - 2011-12-05 : 08:28:02
|
Hey everyone,I'm trying to do a custom forecast but I'm having trouble. I need to extractall records where the MaturityDate is less than 3 months away from theexisting month(sdate). The existing date I'm going to forecast 3 months from is a field called sdatewhich is constant between all records. I can't seem to get it to work. maturity < DateAdd(Month,3,sdate.value?)Any help would be greatly appreciated.SteveSteve |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-12-05 : 09:55:26
|
is sdate a column with the same value in all rows?select *from tblwhere maturity < DateAdd(Month,3,sdate)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
steve_r18
Yak Posting Veteran
59 Posts |
Posted - 2011-12-05 : 10:06:06
|
When I do it as such (as I had already tried) it seems to not be adding the 3 months as the comparison value and just using the original SDATE value. So the records returning are those with the Maturity less than the SDATE. Any ideas why this might be the case?quote: Originally posted by nigelrivett is sdate a column with the same value in all rows?select *from tblwhere maturity < DateAdd(Month,3,sdate)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
Steve |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-12-05 : 10:14:01
|
I doubt that.try this to see what is happeningselect maturity , sdate, DateAdd(Month,3,sdate)from tblwhere maturity < DateAdd(Month,3,sdate)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
steve_r18
Yak Posting Veteran
59 Posts |
Posted - 2011-12-05 : 10:25:11
|
Thanks for the quick replies Nigel, it seems in my own work I was actually using a non constant date field (not intented). Now that I have the right field my original formula works. Thanks again!Cheers.quote: Originally posted by nigelrivett I doubt that.try this to see what is happeningselect maturity , sdate, DateAdd(Month,3,sdate)from tblwhere maturity < DateAdd(Month,3,sdate)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
Steve |
|
|
|
|
|
|
|