I want to set a field in my table based on another field in the table.
This is the functionality that I want:
set result = Win if ((select status from tableY) like '%Won%')
set result = Loss if ((select status from tableY) like '%lost%')
This does not compile... How do I get the correct functionality?
set result = case when (select status from tableY) like '%Won%'
then 'Win'
when (select status from tableY) like '%lost%'
then 'Lost'
-- If neither win or lose don't change a thing
else result
end
So, you're trying to update a column in tableY?
UPDATE tableY SET Result = CASE WHEN status LIKE '%Won%' then 'Win'
ELSE 'Loss'
END
WHERE (status LIKE '%Won%' AND COALESCE(Result,'') != 'Win')
OR (status LIKE '%Lost%' AND COALESCE(Result,'') != 'Loss')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With