How do I put an 'if clause' in an SQL string?

前端 未结 9 1389
误落风尘
误落风尘 2021-01-29 18:16

So here\'s what I want to do on my MySQL database.

I would like to do:

SELECT *
    FROM itemsOrdered
    WHERE purchaseOrder_ID = \'@purchaseOr         


        
9条回答
  •  被撕碎了的回忆
    2021-01-29 18:41

    if not exists(select top 1 fromFROM itemsOrdered
        WHERE purchaseOrder_ID = '@purchaseOrdered_ID'
            AND status = 'PENDING' )
    Begin
    
    UPDATE purchaseOrder 
        SET purchaseOrder_status = 'COMPLETED'
        WHERE purchaseOrder_ID = '@purchaseOrder_ID
    
    End
    

提交回复
热议问题