teradata SQL sequence generation

Hi Folks,

I would like to insert records into the Reference table(xref_subject_area) from stage table(detail_stg) in sequence order, when do not have records in reference table where as present in the stage table. please find below is table structures:

Re: teradata SQL sequence generation

INSERT INTO xref_subject_area SEL ( SEL MAX(subject_area_Id) AS mx FROM xref_subject_area) + ROW_NUMBER () OVER ( ORDER BY subject_area_Nm), subject_area_Nm, subject_area_Nm||' desc' FROM detail_stg WHERE subject_area_Nm NOT IN ( SELECT subject_area_Nm FROM xref_subject_area)

Hi Murali,

This will be what you can use. Your post is not clear on what columns are basis of sequence ordering so I have ordered them by subject name.