一项目有这个需求,顺便将代码贴上,共同学习。
/****** 定义输入参数 ******/
ALTER proc [dbo].[upkeywords]
@inkeyval nvarchar(100),
@inkeycompete int,
@inkeyinclude int,
@inKeyID int
as
DECLARE
/****** 定义变量 ******/
@keyval nvarchar(100),
@keycompete int,
@keyinclude int,
@KeyID int
/****** 给变量赋原来的值 ******/
set @keyval=(select KeyVal from Keywords where KeyID=@inKeyID)
set @keycompete=(select keycompete from Keywords where KeyID=@inKeyID)
set @keyinclude=(select keyinclude from Keywords where KeyID=@inKeyID)
/****** 如果传入的参数是NULL,就将原来的值还给它 ******/
update Keywords set
KeyVal=ISNULL(@inkeyval,@keyval),
keycompete=ISNULL(@inkeycompete,@keycompete),
keyinclude=ISNULL(@inkeyinclude,@keyinclude)
where KeyID=@inKeyID