Search This Blog

Saturday, January 15, 2011

%InsertSelect

%InsertSelect(AE_SECTION_TBL, AE_STEP_TBL S, AE_SECTION_TYPE = ' ')
FROM PS_AE_STEP_TBL S, PS_AS_STMT_TBL T
WHERE. . .

The example code resolves into the following:

INSERT INTO PS_AE_SECTION_TBL (AE_APPLID, AE_SECTION,. . ., AE_SECTION_TYPE)
SELECT S.AE_APPL_ID, S.AE_SECTION, . . . ' '
FROM PS_AE_STEP_TBL S, PS_AS_STMT_TBL T
WHERE. . .

In the following example, you have a temporary table, PS_MY_TEMP, which is based on a join between two other tables, PS_MY_TABLE1 and PS_MY_TABLE2:

%InsertSelect(MY_TEMP, MY_TABLE1, MY_TABLE2 T2)
FROM PS_MY_TABLE1 T1, PS_MY_TABLE2 T2
WHERE %Join(COMMON_KEYS, MY_TABLE1 T1, MY_TABLE2 T2) . . .

This code resolves into:

INSERT INTO PS_MY_TEMP (FIELD1, FIELD2 . . .)
SELECT T2.FIELD1, T2.FIELD2, . . .
FROM PS_MY_TABLE1 T1, PS_MYTABLE2 T2
WHERE T1.FIELD1 = T2.FIELD1
AND T1.FIELD2 = T2.FIELD2 . . .

The following example creates a distinct Select statement.

%InsertSelect(DISTINCT, MY_TABLE, TABLE1, TABLE2 T2)
FROM PS_TABLE1 T1, PS_TABLE2 T2
WHERE %Join(COMMON_KEYS, TABLE1 T1, TABLE2 T2) . . .

This code resolves into:

INSERT INTO PS_MYTABLE (FIELD1, FIELD2 . . .)
SELECT DISTINCT T2.FIELD1, T2.FIELD2, . . .
FROM PS_TABLE1 T1, PS_TABLE2 T2
WHERE T1.FIELD1 = T2.FIELD1
AND T1.FIELD2 = T2.FIELD2 . . .

No comments:

Post a Comment