Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Bulk Loading - response (4) by Adharssh

$
0
0

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. 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>