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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-08 : 17:56:50
|
| Josh writes "Some background,I am developing a financial planning application for the company I work for. I need to create a stored procedure that looks at the current reporting month (contained in a table) and then generates a dynamic forecast (meaning that for the 12 months of the year it pulls from the actuals table up to the current reporting month and then pulls the remaining months values from the forecast table) An example would be if the current reporting month is march the stored procedure should use data from the actuals table for jan, feb, and mar; then use data from the forecast table for the remaining months.The question,How can I create a stored procedure that conditionally determines which fields to include in a select query based on a provided value.Thanks" |
|
|
Lou
Yak Posting Veteran
59 Posts |
Posted - 2002-02-08 : 19:06:49
|
| Try this. Note the datediff will subtract month from @month, in months.-- argument@month datetime-- use actuals up to this monthselect *from actualswhere datediff(m,month,@month) >= 0UNION-- use forecast beyond this monthselect *from forecastwhere datediff(m,month,@month) < 0 |
 |
|
|
|
|
|