- 類(lèi)型:數(shù)據(jù)庫(kù)類(lèi)大。331KB語(yǔ)言:英文 評(píng)分:6.6
- 標(biāo)簽:
MSSQL 存儲(chǔ)過(guò)程實(shí)現(xiàn)更新,如果要更新的字段內(nèi)容為空,則該字段不作變更,只更新其他字段
一項(xiàng)目有這個(gè)需求,順便將代碼貼上,共同學(xué)習(xí)。
/****** 定義輸入?yún)?shù) ******/
ALTERproc[dbo].[upkeywords]
@inkeyvalnvarchar(100),
@inkeycompeteint,
@inkeyincludeint,
@inKeyIDint
as
DECLARE
/****** 定義變量 ******/
@keyvalnvarchar(100),
@keycompeteint,
@keyincludeint,
@KeyIDint
/****** 給變量賦原來(lái)的值 ******/
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)
/****** 如果傳入的參數(shù)是NULL,就將原來(lái)的值還給它 ******/
update Keywords set
KeyVal=ISNULL(@inkeyval,@keyval),
keycompete=ISNULL(@inkeycompete,@keycompete),
keyinclude=ISNULL(@inkeyinclude,@keyinclude)
where KeyID=@inKeyID