For simplicity say I have a column 'Hour' which is either the value 10, or 12. I wish to update a new column, Hour_type which will be 'A' if the Hour value is 10 or B if 12 and so on. I can output a column, 'Hour_type' by using CASE, as follows
SELECT CASE WHEN Hour = 10 then 'A'
WHEN hour = 12 then 'B'
else 'c'
end
as Hour_type
from Traffic_Counts
This outputs the correct answer but does not insert the values into the table.
I wish to set a column which exists in the table with these values.
SELECT CASE WHEN Hour = 10 then 'A'
WHEN hour = 12 then 'B'
end
as Hour_type
from Traffic_Counts set Hour_type = Hour_type
This results in a Syntax error.
In pseudocode I am trying to add an 'if' to this simple update column
update table set Hour_type = 'a' if Hour = 10,
'b' if Hour = 12;