How the below statement will execute? Please explain?

Database
Enthusiast

How the below statement will execute? Please explain?

Hi,

Please explain how the below statement will execute?
SELECT ';INSERT INTO x_data_hist.hist_x
(
Seg_ID,
Group_ID,
Individual_ID,
Agreement_ID,
Sel_Ind,
Ctl_Ind,
Mail_Ind,
Rsp_Ind,
Target_Ind,
Dup_Ind
)
SELECT S.Seg_ID,
S.Group_ID,
S.Individual_ID,
S.Agreement_ID,
S.Sel_Ind,
S.Ctl_Ind,
S.Mail_Ind,
S.Rsp_Ind,
S.Target_Ind,
S.Dup_Ind
FROM x_data.'||TRIM(TBL_NM)||' S
WHERE S.Sel_Ind = ''Y''
AND (S.Mail_Ind = ''Y''
OR
S.Ctl_Ind = ''Y'')'
(title '')
FROM x_work.work_x_table
WHERE Seg_Typ_Id NOT IN (15,17)
GROUP BY Tbl_Nm;

How the insert statement will execute ..... Please explain...

Thanks.
3 REPLIES
Enthusiast

Re: How the below statement will execute? Please explain?

For every TBL_NM in work_x_table (with a Seg_Typ_Id other than 15 or 17), it will generate an insert statement to copy the appropriate records into the hist table.
These statements are presumably being exported to a file which is then being RUN from BTEQ.
Enthusiast

Re: How the below statement will execute? Please explain?

Thanks Jimm.
One more help needed.
we have the cloumn seg_nm like 'remainder%' in the above TBL_NM table. We don't want to store the data related to seg_nm like 'remainder%' in the target table x_data_hist.hist_x. Can you please provide code for this one.Because am new to teradata.

Thanks.
Enthusiast

Re: How the below statement will execute? Please explain?

SELECT ';INSERT INTO x_data_hist.hist_x
(
Seg_ID,
Group_ID,
Individual_ID,
Agreement_ID,
Sel_Ind,
Ctl_Ind,
Mail_Ind,
Rsp_Ind,
Target_Ind,
Dup_Ind
)
SELECT S.Seg_ID,
S.Group_ID,
S.Individual_ID,
S.Agreement_ID,
S.Sel_Ind,
S.Ctl_Ind,
S.Mail_Ind,
S.Rsp_Ind,
S.Target_Ind,
S.Dup_Ind
FROM x_data.'||TRIM(TBL_NM)||' S
WHERE S.Sel_Ind = ''Y''
AND (S.Mail_Ind = ''Y''
OR
S.Ctl_Ind = ''Y'')'
(title '')
FROM x_work.work_x_table
WHERE Seg_Typ_Id NOT IN (15,17)
---------------- New Code -----
AND seg_nm NOT LIKE 'remainder%'
---------------- End Of New ----------------
GROUP BY Tbl_Nm;

That should sort out your Market Research!