troubleshooting Question

field in  query that needs to be calculated from 3 other fields

Avatar of Fordraiders
FordraidersFlag for United States of America asked on
Microsoft SQL ServerSQL
7 Comments1 Solution60 ViewsLast Modified:
field in a query that will be the result of a caluclation on 3 other fields.

I have a field in a query that needs to be calculated from 3 other fields
(K3/I3)*H3

, NULL AS  Sales_Projection_Thru_end_of_term  -- calculation  needs to look at (Sales_From_Start_To_End_Rebate_Date / Months_Completed_RB1) * terms_in_month_RB1

is this possible ?

here is the query
SELECT --CustomerName --  cspt.[Customer  Name]  -- yes CustomerName
      ContractName --  [Master Agreement Name] --yes ContractName
      ,right(clm.BusinessPartnerCode,9) as BusinessPartnerCode --[BP Code] --  businesspartnercode
      ,contract_number --[Master Agreement ID]  --yes  contract_number
      ,RSVP_Dir --[RSVP/Director]  --yes RSVP_Dir
       ,Sales_Manager --yes  Sales_Manager
       ,CR1.Start_Date as Rebate_Start_Date1  
       , CR1.End_Date AS Rebate_End_Date1
       , DATEDIFF(MONTH, CR1.Start_Date, CR1.End_Date) AS 'terms_in_month_RB1' --terms in month -  calculation
       , DATEDIFF(MONTH, CR1.Start_Date, getdate()) AS 'Months_Completed_RB1' -- Mon. comp.
      , null as Conversion_Allowance -- conversion allowance   from contract
      ,ctct.[sls_total]   AS Sales_From_Start_To_End_Rebate_Date --Sales from start thru 12/31/18 (or rebate end date)
      , (Sales_From_Start_To_End_Rebate_Date / Months_Completed_RB1) * terms_in_month_RB1  AS  "Sales_Projection_Thru_end_of_term"  -- calculation i'm trying to do


Msg 207, Level 16, State 1, Line 17
Invalid column name 'Sales_From_Start_To_End_Rebate_Date'.
Msg 207, Level 16, State 1, Line 17
Invalid column name 'Months_Completed_RB1'.
Msg 207, Level 16, State 1, Line 17
Invalid column name 'terms_in_month_RB1'



Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros