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

后端 未结 8 965
灰色年华
灰色年华 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 09:27

    As long as you need to find it based on Count just more than 0, it is better to use EXISTS like this:

    IF EXISTS (SELECT 1 FROM INCIDENTS  WHERE [Some Column] = 'Target Data')
    BEGIN
        -- TRUE Procedure
    END
    ELSE BEGIN
        -- FALSE Procedure
    END
    

提交回复
热议问题