spiff2002
IS-IT--Management
- Jan 31, 2003
- 40
Hi all
I'm trying to create a sales goal table
My current query looks like this
There some problems:
1. Calculating goalmar (goals for the month of March)
should be
In this case I replaced "goalfeb" with the new definition of goalfeb "goalfeb-((salesjan-goaljan)/11)". Can I create a variable called newgoalfeb=goalfeb-((salesjan-goaljan)/11)???
2. This has to be done for all months so if I'm able to create functions or variables, that would save me a lot of coding.
Like you can see I'm very confused
I'm new to MS SQL and I'm not familir with variables or user defined functions.
Thanks a lot
Spiff
I'm trying to create a sales goal table
My current query looks like this
Code:
select
brand,
goal,
state,
goaljan,
goalfeb-((salesjan-goaljan)/11) as goalfeb,
case
when month(getdate())>=2 then goalmar-(((salesfeb-goalfeb)/10)+((salesjan-goaljan)/11))
when month(getdate())=1 then goalmar-((salesjan-goaljan)/11)
end as goalmar,
case
when month(getdate())>=3 then goalapr-(((salesmar-goalmar)/9)+((salesfeb-goalfeb)/10)+((salesjan-goaljan)/11))
when month(getdate())=2 then goalapr-(((salesfeb-goalfeb)/10)+((salesjan-goaljan)/11))
when month(getdate())=1 then goalapr-((salesjan-goaljan)/11)
end as goalapr
from sales
There some problems:
1. Calculating goalmar (goals for the month of March)
should be
Code:
case
when month(getdate())>=2 then goalmar-(((salesfeb-goalfeb-((salesjan-goaljan)/11))/10)+((salesjan-goaljan)/11))
when month(getdate())=1 then goalmar-((salesjan-goaljan)/11)
end as goalmar
2. This has to be done for all months so if I'm able to create functions or variables, that would save me a lot of coding.
Like you can see I'm very confused
I'm new to MS SQL and I'm not familir with variables or user defined functions.
Thanks a lot
Spiff