SQL if not null update

前端 未结 5 1697
忘掉有多难
忘掉有多难 2021-01-26 03:18

I have this query

UPDATE users SET username = Param1,email = Param2,PASSWORD = Param3 WHERE id = Param4;

this is updating my user row, but

5条回答
  •  无人及你
    2021-01-26 03:37

    Please check if this works..

     DECLARE @email varchar(100), @password varchar(50)
        SET @email = null  
        SET @password = null
    
        IF @email <= (SELECT email from users WHERE id = Param4)   
        UPDATE users SET username = Param1,email = Param2,PASSWORD = Param3 WHERE id = Param4;
    
        IF @password <= (SELECT PASSWORD from users WHERE id = Param4)   
        UPDATE users SET username = Param1,email = Param2,PASSWORD = Param3 WHERE id = Param4;
    

提交回复
热议问题