Combine two arrays. for in for ?..

The overall approach seems a bit complex, selecting rows with identical criteria from a few different tables. How about serving a single db2 invocation a script, selecting all the criteria with an IN clause from a table, and running this across the tables needed? Letting the shell do (almost) all the transformations, although that needs some shell variable crisscross. Like

ARGLIST=$(sed -n ":L; N; \${s/\n/','/g; s/^\|$/'/g; p; q};  bL; " file2)

TABLES=( $(<file1) )
IFS=$'\n'
TABLES=( ${TABLES
[*]/#/select DOCID from ICMADMIN.} )
db2  <<< "${TABLES
[*]/%/ where ITEMID in ($ARGLIST);}"
select DOCID from ICMADMIN.NNDTY4_DOC_05001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
select DOCID from ICMADMIN.NNDTY5_DOC_05001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
.
.
.
select DOCID from ICMADMIN.NZGPIM_DAT_01001 where ITEMID in ('A1001001A19D02A60148J20560','A1001001A19D02A60149F20562','A1001001A19D02A60149F20566','A1001001A19D02A60149F20564','A1001001A19D02A60149F20568','A1001001A19D02A60150B20570','A1001001A19D02A60150B20572','A1001001A19D02A60150B20574','A1001001A19D02A60150E20578','A1001001A19D02A60150E20576');
IFS=$' \t\n'

1 Like

Thank you!
It works now.
Here is the script. I generate first an SQL file and then give it to db2.

ARGLIST=$(sed -n ":L; N; \${s/\n/','/g; s/^\|$/'/g; p; q};  bL; " ITEMID.txt)
TABLES=( $(<et.txt) )
IFS=$'\n'
for ((i=0;i<${#TABLES[@]};i++))
do
        echo "echo Elementtyp: ${TABLES[$i]}"
        TABES=( ${TABLES[$i]/#/select DOCID from ICMADMIN.} )
        echo "$TABES where ITEMID in ($ARGLIST)"
done