I have the following UPDATE statement:
update MESSAGES set status=
(select (CASE
WHEN from_id='111111111'
THEN (CASE
WHEN status='A'
THEN 'S'
WHEN status='R'
THEN 'D'
END)
WHEN to_id='111111111'
THEN (CASE
WHEN status='A'
THEN 'R'
WHEN status='S'
THEN 'D'
END)
END)
as status_value)
where primary_key='236499681204'
and status_value not null ;
The problem with this query is, at the last line, status_value is not recognized. If I remove the last comparison, and status_value not null, it works. I dint expect the above version to work, but could someone tell me an alternative that would achieve the same?
Is there a way I can use the AS keyword in the UPDATE query to define the variable status_value?
Edit
The actual requirement is not just that i check if status_value is null, but also that I dont perform any update if it is null
Try to add
ELSE STATUSand removeand status_value not null:You can also try to use
viewor you can use
case in condition