Link to home
Start Free TrialLog in
Avatar of thayduck
thayduckFlag for United States of America

asked on

Case Statement Rewrite

select top (@IntTopRecords) m.unit, m.[Year], m.[Make], m.Model, SUM(case when r.rec > 0 then -r.rec else r.Labour + r.Parts + (r.cshop + r.cpart + r.clab) end) as TotalCost            
            from dbo.Repair r  


How would I rewrite above   sum(case    statement so

 if r.ca = 'R'  then I want to :
SUM(case when r.rec > 0 then -r.rec else r.Labour + r.Parts + (r.cshop + r.cpart + r.clab) end)

and if  r.ca <> 'R'  then I want to:      
SUM(case when r.rec > 0 then -r.rec else (r.cshop + r.cpart + r.clab) end)

as TotalCost
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thayduck

ASKER

Perfect, thanks...