DB2 Where IN (2 of 2)

Refer my installment #1 if you miss it.

Select Empno, Lastname, Firstname

From Emp

Where Empno IN (:HV1, :HV2, ;Hv3)

Though it saves time, it needs more Host variables.

If we need to give multiple host variable ,we can put all those  in a Temp table and retrieve it.

step1:

EXEC SQL DECLARE GLOBAL TEMPORARY TABLE  TEST1(COL_LIST  INTEGER  NOT NULL);

step2:

EXEC SQL INSERT INTO TEST1 VALUES (x1,x2,x3);

Step3:

EXEC SQL COMMIT;

step4:

Select Empno, Lastname, Firstname

From Emp

Where Empno IN (Select COL_LIST from TEST1);

To drop the table:

DROP TABLE TEST1;

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.