SQL Server INSERT INTO with WHERE clause

后端 未结 7 1146
礼貌的吻别
礼貌的吻别 2021-01-05 05:39

I\'m trying to insert some mock payment info into a dev database with this query:

INSERT
    INTO
        Payments(Amount)
    VALUES(12.33)
WHERE
    Paymen         


        
7条回答
  •  孤街浪徒
    2021-01-05 06:10

    Better solution and without risk of deadlocks:

    UPDATE Payments
        SET Amount = 12.33
    WHERE CustomerID = '145300'
    
    INSERT INTO Payments(CustomerID,Amount)
        SELECT '145300',12.33
    WHERE @@ROWCOUNT=0
    

提交回复
热议问题