1
WITH RowNumbers AS 
(   
    SELECT 
        ROW_NUMBER() OVER (ORDER BY G TLINE) AS row_num, 
        gtline, gttran  
    FROM 
        GPOTRSP
) 
UPDATE b  
SET b.gtline = a.row_num 
FROM GPOTRSP b  
JOIN RowNumbers a ON b.gtline <> a.gtline  
                  AND b.gttran = a.gttran

I want to resequence the line no after deletion on one record.

1
  • 3
    Please add the results of running that statement to your question. If you got an error, what was the complete error? Commented Feb 28 at 12:46

1 Answer 1

0

Direct update with CTE (WITH) is not supported in DB2 for i.

you can store the results in a temporary table and update GPOTRSP.

Instead of using a JOIN, updates each row by matching its gtline and gttran in the subquery that calculates new row numbers.

Try this ......

DECLARE GLOBAL TEMPORARY TABLE TEMP_GTLINE AS (
    SELECT ROW_NUMBER() OVER (PARTITION BY gttran ORDER BY gtline) AS new_gtline,
           gtline,
           gttran
    FROM GPOTRSP
) WITH DATA;


UPDATE GPOTRSP AS b
SET gtline = (SELECT new_gtline 
              FROM SESSION.TEMP_GTLINE AS a
              WHERE a.gttran = b.gttran 
              AND a.gtline = b.gtline);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.