I have the following SQL statement:
update data
set [sub_st_pc]=
case
when [R 6] is not null then [R 6]
when [R 5] is not null then [R 5]
when [R 4] is not null then [R 4]
when [R 3] is not null then [R 3]
when [R 2] is not null then [R 2]
else sub_st_pc
end
but I need to update another column according to each when, something like this:
when [R 6] is not null then [R 6], [temp] = 6
when [R 5] is not null then [R 5], [temp] = 5
which I know it’s wrong.
Any ideas?
You can use COALESCE to make setting the first column easier. You’ll need a separate CASE statement to set
[temp], and COALESCE won’t help you there.