我有一个这样的更新语句,它试图执行更新。在我的 SPROC 中,我要么传入 2 个参数之一(@TransactAutoID 或 @ReceiptNo),要么同时传入这两个参数。我想要做的是如果@TransactAutoID 为空,那么我将使用@ReceiptNo 作为第二选择来代替它。是否有更好或更有效的编写方式,因为据我了解,“或”运算符仍将继续执行此操作:
OR (@ReceiptNo IS NOT NULL AND [AutoID] = (SELECT Max(AutoID)
FROM [Transact]
WHERE [ReceiptNo] = @ReceiptNo)
即使@TransactAutoID 不为空。谢谢。
UPDATE [Transact]
SET [VoidBy] = @VoidedBy,
[VoidOn] = Getdate(),
[VoidReason] = @VoidedReason
WHERE (@TransactAutoID IS NOT NULL
AND [AutoID] = @TransactAutoID)
OR (@ReceiptNo IS NOT NULL AND [AutoID] = (SELECT Max(AutoID)
FROM [Transact]
WHERE [ReceiptNo] = @ReceiptNo)