I finally found a great solution. Here it is:
-- Update SequenceNumber - 1st step, copy generated number to
SequenceNumber
UPDATE #outCOMMENTS
SET SequenceNumber = GeneratedSeq
-- Update SequenceNumber - 2nd step, change SequenceNumber to start with
1, 2 etc. for each PPOID
UPDATE #outCOMMENTS
SET SequenceNumber = (SELECT COUNT(*) FROM #outCOMMENTS C2
WHERE #outCOMMENTS.PPOID = C2.PPOID AND
#outCOMMENTS.SequenceNumber >= C2.SequenceNumber)
> Hi.
>
> I have a very perplexing problem. I sent out a previous message
regarding
> changing a variable value between several unions. However, I don't think
> that logic will work with what I'm trying to achieve.
>
> The end result of a COMMENT table should look like this:
> PPOID SequenceNumber Comment
> ----- -------------- -------
> ABC 1 This is comment1 for ABC
> ABC 2 This is comment2 for ABC
> ABC 3 This is comment3 for ABC
> DEF 1 This is comment1 for DEF
> GHI 1 This is comment1 for GHI
> GHI 2 This is comment2 for GHI
>
> To achieve this result, I have multiple INSERT INTO COMMENT statements.
>
> My problem is the SequenceNumber column. This column always has to start
> at "1" when the PPOID is different.
>
> I thought about creating a temp table with no SequenceNumbers and then
> doing an UPDATE on the temp table to get the correct SequenceNumber.
>
> Using an UPDATE statement, how could I change the SequenceNumbers,
always
> starting with "1" on a PPOID change?
>
> TIA.
>
> Rita