What would be the syntax for doing the following:
INSERT INTO table
SET
IF *expression*
column1 = 'value1'
ELSE
column2 = 'value2'
What would be the syntax for doing the following:
INSERT INTO table
SET
IF *expression*
column1 = 'value1'
ELSE
column2 = 'value2'
You would use insert . . . select
with a case
statement:
INSERT INTO table(column1, column2)
select (case when *expression* then 'value1' end) as column1,
(case when not *expression* then 'value2' end) as column2;
However, I suspect that you might really want an update
and not an insert
:
update table
set column1 = (case when *expression* then 'value1' else column1 end),
column2 = (case when not *expression* then 'value2' else column2 end);