Translate

Thursday, July 24, 2025

TSQL - Set A Variable While Updating

I needed to set the value in a variable and update a field at the same time This is the update query.

DECLARE @numberOfCountersNeeded as int;
DECLARE @newcounterval as bigint;
SET @numberOfCountersNeeded = 3
UPDATE c --get the counter interval and update the current count
SET @newcounterval = somefield = somefield + @numberOfCountersNeeded
FROM sometable c
WHERE conditions

No comments:

Post a Comment

Thank you for commenting!