DB2 SQL: How to check Host-variables (2 of 2)

Refer my installment #1 if you miss it. In this post, I have shared two different ideas to give host-variables in DB2 SQL.

SQL Query

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  
      <em>TEST1</em>(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;

Related Tables

Author: Srini

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