shelly
shelly

Reputation: 319

SQL update (case) multiple values

i need to update different columns based on their values:

UPDATE tablename

set date1 = case
    when mytime < '01.08.2020' then mytime
end,
set date2 = case
    when mytime < '01.08.2020' then mytime
end

where something = 1;

In the 2nd set block im getting the error, that the column (date2) is invalid.

Upvotes: 1

Views: 81

Answers (1)

Fahmi
Fahmi

Reputation: 37473

You don't need set multiple times for multiple columns

UPDATE tablename set 
    date1 = case when mytime < '01.08.2020' then mytime end, 
    date2 = case when mytime < '01.08.2020' then mytime end
where something = 1;

Upvotes: 2

Related Questions