Errol Farro
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='Su perior' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 22
else
when SoldInventory.RoomType='De luxe' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 26
else
when SoldInventory.RoomType='Ro yal' and SoldInventory.Week>=15 and SoldInventory.Week<=50 then 32
else
when SoldInventory.RoomType='Su perior' then 35
else
when SoldInventory.RoomType='De luxe' then 39
else
when SoldInventory.RoomType='Ro yal' 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
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='Su
else
when SoldInventory.RoomType='De
else
when SoldInventory.RoomType='Ro
else
when SoldInventory.RoomType='Su
else
when SoldInventory.RoomType='De
else
when SoldInventory.RoomType='Ro
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good to hear!
Mike
P.S. sorry about the missing space :)
Mike
P.S. sorry about the missing space :)
ASKER