我今天遇到了这个存储过程,我对它的语法感到困惑。它正在进行更新,查询如下所示:
DECLARE @TransactionStatus tinyint = 1,
@RedeemedAmount decimal(18,2) = 0,
@PromotionCodeAmount decimal(18,2) = 0,
@EventDetailId int = 0
UPDATE PED
SET @RedeemedAmount = PED.RedeemedAmount = PED.RedeemedAmount + PE.PromoCodeAmount,
@PromotionCodeAmount = PE.PromoCodeAmount,
@EventDetailId = PED.Id
FROM dbo.PromotionEvents AS PE
JOIN dbo.PromotionEventDetails AS PED ON PED.EventId = PE.Id
WHERE PED.Id IN (
SELECT TOP 1 PED.ID
FROM dbo.PromotionEvents AS PE
JOIN dbo.PromotionEventDetails AS PED ON PED.EventId = PE.Id
WHERE PE.Id = @EventId
AND PED.Amount >= PED.RedeemedAmount + PE.PromoCodeAmount
AND PE.StartDate <= GETDATE() AND PE.EndDate > GETDATE()
AND PE.MStatusId = 1
AND PED.MStatusId = 1
ORDER BY PED.CreatedDateTime)
这只是整个存储过程的一部分。我只需要了解这部分的作用吗?
SET @RedeemedAmount = PED.RedeemedAmount = PED.RedeemedAmount + PE.PromoCodeAmount,
请注意,该行上有两个等号。
答案 0 :(得分:2)
该行同时做两件事:
PromotionEventDetails.RedeemedAmount
列@RedeemedAmount
变量这似乎是通常的UPDATE ... SET column = expression
与SQL Server的{set 1}}的“set variable”语法的混合。测试显示无法执行SET @variable = expression
或@a = @b = col1
,它仅适用于一个变量和一个目标列。