我创建表
CREATE TABLE tbl
(
ID int,
FirstName nvarchar(50),
LastName nvarchar(50)
)
存储过程
UPDATE tbl
SET FistName = @firstName , LastName = @lastName
WHERE ID = @ID
现在,当我调用我的存储过程时,exec myProc 1,'John',''
需要更新
只有我写的那些专栏。例如,如果我在表格中有值:
ID : 1
FirstName: Bob
LastName : Brown
在exec之后必须是
ID : 1
FirstName: John
LastName : Brown
答案 0 :(得分:8)
试试这个:
UPDATE tbl
SET FirstName =
case
when @firstName is null or @firstName = '' then firstName
else @firstName
end,
LastName =
case
when @lastName is null or @lastName = '' then lastName
else @lastName
end
WHERE ID = @ID
一般来说管理NULL和空字符串值
是正确的