Hi,
The Following Code Snippet will work,
Assuming that your target table has 3 fields, COLUMNPI,COLUMN1,COLUMN2 and Source hastow fields COL1,COL2.
INSERT INTO TARGET_TABLE
(
COLUMNPI,
COLUMN1,
COLUN2
)
SEL
CASE WHEN TT.MAXI IS NULL
THEN ROW_NUMBER() OVER( ORDER BY COLUMN1,COLUMN2)
ELSE
TT.MAXI + CAST(ROW_NUMBER() OVER( ORDER BY COLUMN1,COLUMN2)
END AS COLUMNPI,
COL1,
COL2
FROM SOURCE_TABLE
LEFT OUTER JOIN
( SEL MAX(COLUMNPI) AS MAXI
FROM
TARGET_TABLE
) TT
ON 1=1
;
The Row_number function will always gives you distinct of values. Or, We can go for the Identity Column.
CREATE MULTISET TABLE TARGET_TABLE
(COLUMNPI INTEGER GENERATED ALWAYS AS IDENTITY
(START WITH 1 INCREMENT BY 1
MINVALUE -2147483647
MAXVALUE 2147483647 NO CYCLE),
COLUMN1,
COLUMN2
);
INSERT INTO TARGET_TABLE
(
COLUMN1,
COLUMN2
)
SELECT
COL1,
COL2
FROM SOURCE_TABLE;
Thanks & Regards,
Adharssh.
Hi,
The Following Code Snippet will work,
Assuming that your target table has 3 fields, COLUMNPI,COLUMN1,COLUMN2 and Source hastow fields COL1,COL2.
The Row_number function will always gives you distinct of values. Or, We can go for the Identity Column.
Thanks & Regards,
Adharssh.