[英]Conditional Stored Procedure in SQL Server 2012
當 2 列(例如 a 和 b)之間的差異大於 0.01 時,我正在嘗試更新記錄。 我不精通存儲過程或 T-SQL,但我想要類似的東西
if (a - b > 0.01)
then update statement
解決這個問題的正確策略是什么?
如果 a 是來自多個表的列的計算值 -
如果a
列有要更新的話,最好使用表的表的關系Join
和列WHERE
條件。
Update t
SET Column = ''
From Table t
Join Table1 t1 on t1.a = t.a
WHERE (t.a - b) > 0.01
如果a and b
列與您的更新表沒有關系,您可以使用IF ELSE
語句
Declare @a int = 1, @b int = 2
IF (@a-@b > 0.01)
BEGIN
-- If you have Update statement without condition then it will update all the Column records
END
ELSE
BEGIN
Print 'FALSE'
-- code block run when condition is FALSE
END
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.