April 13, 2018 at 9:54 am
April 13, 2018 at 10:30 am
Add another variable to hold the previous group value, so you can store the current and previous values in variables.
On each loop, update current value via cursor, compare it to the previous value, compare them to set count appropriately, set the previous value to the current value, and loop again.
Be sure to set the initial value of the previous group variable to some dummy value (something other than null).
April 13, 2018 at 11:30 am
What this code is trying to attempt could be easily rewritten by something like this:
WITH cteCustomer AS(
SELECT CustomerNumber
, Group
, PrintGroup
, DENSE_RANK() OVER(ORDER BY Group) GroupCount
FROM Customer
)
UPDATE cteCustomer
SET PrintGroup = GroupCount;
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply