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.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Forecasting

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 extract
all records where the MaturityDate is less than 3 months away from the
existing month(sdate).

The existing date I'm going to forecast 3 months from is a field called sdate
which 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.

Steve

Steve

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 tbl
where 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.
Go to Top of Page

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 tbl
where 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
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-05 : 10:14:01
I doubt that.
try this to see what is happening

select maturity , sdate, DateAdd(Month,3,sdate)
from tbl
where 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.
Go to Top of Page

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 happening

select maturity , sdate, DateAdd(Month,3,sdate)
from tbl
where 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
Go to Top of Page
   

- Advertisement -