SQL Stored Procedure: If variable is not null, update statement

前端 未结 3 1840
孤街浪徒
孤街浪徒 2021-02-05 05:53

I have an update statement in a stored procedure that looks generally like this:

Update [TABLE_NAME]
Set XYZ=@ABC

Is there a good way to only t

3条回答
  •  鱼传尺愫
    2021-02-05 06:20

    Another approach when you have many updates would be to use COALESCE:

    UPDATE [DATABASE].[dbo].[TABLE_NAME]
    SET    
        [ABC]  = COALESCE(@ABC, [ABC]),
        [ABCD] = COALESCE(@ABCD, [ABCD])
    

提交回复
热议问题