Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将三条SQL update语句合并为一条_Sql_Sql Server 2008_Tsql - Fatal编程技术网

将三条SQL update语句合并为一条

将三条SQL update语句合并为一条,sql,sql-server-2008,tsql,Sql,Sql Server 2008,Tsql,我可以一次而不是三次运行这三个update语句吗?我只能找到mysql的例子来说明如何做到这一点 update [NoteAlertLog] set alertmessage = NULL where alertmessage = '' update [NoteAlertLog] set notes = NULL where cast([notes] as nvarchar(max)) = '' update [NoteAlertLog] set externalnotes

我可以一次而不是三次运行这三个update语句吗?我只能找到mysql的例子来说明如何做到这一点

update    [NoteAlertLog]
set alertmessage = NULL where alertmessage = ''

update    [NoteAlertLog]
set notes = NULL where cast([notes] as nvarchar(max)) = ''

update    [NoteAlertLog]
set externalnotes = NULL where cast(externalnotes as nvarchar(max)) = ''
我尝试过这样做,但出现语法错误:

update    [NoteAlertLog]
set alertmessage = NULL where alertmessage = ''
,set notes = NULL where cast([filenotes] as nvarchar(max)) = ''
,set externalnotes = NULL where cast(externalnotes as nvarchar(max)) = ''
我试过不使用
设置

update    [NoteAlertLog]
set alertmessage = NULL where alertmessage = ''
,notes = NULL where cast([filenotes] as nvarchar(max)) = ''
,externalnotes = NULL where cast(externalnotes as nvarchar(max)) = ''

使用
case
表达式:

update    [NoteAlertLog]
set alertmessage = case when alertmessage = '' then NULL else alertmessage end,
    notes = case when cast([notes] as nvarchar(max)) = '' then NULL else notes end,
    externalnotes = case when cast(externalnotes as nvarchar(max)) = '' then NULL else externalnotes end

where alertmessage = ''
   or cast([notes] as nvarchar(max)) = ''
   or cast(externalnotes as nvarchar(max)) = ''

where
子句可以跳过,但我会保留它以降低事务大小。

使用
case
表达式:

update    [NoteAlertLog]
set alertmessage = case when alertmessage = '' then NULL else alertmessage end,
    notes = case when cast([notes] as nvarchar(max)) = '' then NULL else notes end,
    externalnotes = case when cast(externalnotes as nvarchar(max)) = '' then NULL else externalnotes end

where alertmessage = ''
   or cast([notes] as nvarchar(max)) = ''
   or cast(externalnotes as nvarchar(max)) = ''

where
子句可以跳过,但我会保留它以降低事务大小。

您可以这样做,但三个独立的查询更简单。嗯,好的。这只是为了抑制受影响的
x行出现三次,我必须在存储过程的另一个区域中说明这一点。如果整个更新只有一个计数,则通过设置
NOCOUNT
更容易解决问题。您可以这样做,但三个独立的查询更简单。嗯,好的。这只是为了抑制受影响的
x行出现三次,我必须在存储过程的另一个区域中说明这一点。如果整个更新只有一个计数,则通过设置
NOCOUNT
更容易解决问题。