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

后端 未结 8 960
灰色年华
灰色年华 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:21

    Not very clear what you mean by

    "I cant find any examples to help me understand how I can use this to run 2 different statements:"

    . Is it using CASE like a SWITCH you are after?

    select case when totalCount >= 0 and totalCount < 11 then '0-10'
                when tatalCount > 10 and totalCount < 101 then '10-100'
                else '>100' end as newColumn
    from (
      SELECT [Some Column], COUNT(*) TotalCount
      FROM INCIDENTS
      WHERE [Some Column] = 'Target Data'
      GROUP BY [Some Column]
    ) A
    

提交回复
热议问题