I came across this stored procedure today and I'm confused with the syntax on it. It is doing an UPDATE and the query looks like this:
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)
This is only a portion of the whole stored procedure. I just need to understand what this part does?
SET @RedeemedAmount = PED.RedeemedAmount = PED.RedeemedAmount + PE.PromoCodeAmount,
Notice that there are two equals signs on that line.