Link to home
Start Free TrialLog in
Avatar of Errol Farro
Errol FarroFlag for Aruba

asked on

Can I use complex CASE conditioning in SQL 2005 with the SUM funtion?

Hi All,

I'm trying to run the following sql query but I get an error msg. What am I doing wrong?


SELECT Owner.OwnerID, Owner.OwnerNumber,

sum
(case
when SoldInventory.RoomType='Superior' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 22
else
when SoldInventory.RoomType='Deluxe' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 26
else
when SoldInventory.RoomType='Royal' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 32
else
when SoldInventory.RoomType='Superior' then 35
else
when SoldInventory.RoomType='Deluxe' then 39
else  
when SoldInventory.RoomType='Royal' then 45
else 0
end) as VotesABC

FROM   Owner AS Owner INNER JOIN Contract AS Contract
ON Owner.OwnerID = Contract.OwnerID
INNER JOIN SoldInventory AS SoldInventory
ON Contract.ContractID = SoldInventory.ContractID

WHERE     (Contract.ContractStatus = 'Active')

group BY Owner.OwnerID, Owner.OwnerNumber

Thanks for your help.

Errol
ASKER CERTIFIED SOLUTION
Avatar of DcpKing
DcpKing
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 Errol Farro

ASKER

Thanks a lot Mike. That took care of the errors. Next time I will add the actual errors. Best regards. Errol
Good to hear!

Mike

P.S. sorry about the missing space :)