UPDATE table_Name SET CASE WHEN @flag = '1' THEN column_A += @new_value WHEN @flag = '0' THEN column_B += @new_value END AS Total WHERE ID = @ID
什么是正确的sql服务器代码呢?
IF @flag = 1 UPDATE table_name SET column_A = column_A + @new_value WHERE ID = @ID; ELSE UPDATE table_name SET column_B = column_B + @new_value WHERE ID = @ID;
这很容易阅读,虽然这是一个非常简单的查询.
这是一个工作示例,由@snyder提供:SqlFiddle.