3

I want to set column value only if it is not blank.

Here is sample

Declare @Temp Varchar(20)

Update Logins
Set ColValue = 
Case When @Temp <> '' Then @Temp Else /* Dont SET Value */ End
Where Code=1

What to write in Else Part ?

I have multiple columns to update and want to apply condition in only single column

DB : SQL SERVER 2008

4

2 回答 2

3

您必须将更新的列设置如下:

Declare @Temp Varchar(20)

Update Logins
Set ColValue = Case When @Temp <> '' Then @Temp 
                    Else ColValue 
               End
Where Code=1
于 2013-05-28T08:51:28.550 回答
0

您可以在 WHERE 中检查您的变量,以便在它为空白时根本不更新

Declare @Temp Varchar(20)

Update Logins
Set ColValue = @Temp
Where Code=1 AND @Temp <> ''
于 2013-05-28T08:56:53.813 回答