Using IF ELSE statement based on Count to execute different Insert statements

后端 未结 8 935
灰色年华
灰色年华 2020-12-01 08:40

While I am searching through my database, I run an INSERT statement if I find that a particular item does not exist, and I run a different INSERT statement if I find one or

8条回答
  •  时光取名叫无心
    2020-12-01 09:41

    IF exists

    IF exists (select * from table_1 where col1 = 'value')
    BEGIN
        -- one or more
        insert into table_1 (col1) values ('valueB')
    END
    ELSE
        -- zero
        insert into table_1 (col1) values ('value') 
    

提交回复
热议问题