I would like to insert a row in a table if a variable has a certain value. I have tried the following:
select foo from bar into @tempvar;
if @tempvar = '1'
begin
insert into t1 (f1, f2) values (v1,v2);
end
end if;
Alas, this d开发者_如何学运维oes not work. Any idea how to do this?
INSERT INTO t1
(f1, f2)
SELECT
v1,
v2
FROM
bar
WHERE
foo = 1
v1
and v2
can be literal values (numbers, strings, etc), they don't have to be columns from bar
. You will get as many INSERT
s as the SELECT
portion returns.
精彩评论