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

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

    one obvious solution is to run 2 separate queries, first select all items that have count=1 and run your insert, then select the items with count>1 and run the second insert.

    as a second step if the two inserts are similar you can probably combine them into one query.

    another possibility is to use a cursor to loop thru your recordset and do whatever logic you need for each line.

提交回复
热议问题