【发布时间】:2020-12-08 04:36:03
【问题描述】:
在下面的查询中,当@test 为0 时,它会将值更新为null。 @test 为 0 时,有什么方法可以保留旧值? (如果@test 为0,则不应该有任何更新)
declare @test bigint
set @test=12
update teacher set dta=(case when @test!=0 then @test end) from teacher
【问题讨论】:
-
为什么你需要使用
CASE表达式,而你可以在运行更新之前检查一次条件
标签: sql-server sql-update case