Compare data and columns script

Hello all,
I have below SQLs to compare data between 2 identical tables.in my database.

Can any body help me to convert this into a script

db2 "select *from TAB1  where PK IN (select PK  from  TAB2) order by BEDG_NR".

Note:
These SQL should run for any given 2 tables as input TAB1 ,TAB2 and same primary key (PK).
This is db2 database

I am not sure about DB2, but you could use something like:

getCompareQuery ()
{
        firTab="${1}"
        secTab="${2}"
        pKey="${3}"
        orderBy="${4}"
        echo "select * from ${firTab} where ${pKey} IN (select ${pKey} from ${secTab}) order by ${orderBy}"
}

## Execute it as follow:
# getCompareQuery "TAB1" "TAB2" "PK" "BEDG_NR"
select *from TAB1 where PK IN (select PK from TAB2) order by BEDG_NR

# compQuery=`getCompareQuery "TAB1" "TAB2" "PK" "BEDG_NR"`
# db2 "${compQuery}"

Regards!

Hi ,
Thanks for the reply i have written like this and ran the script using below commands

$ ./cmpre.sh s1 tab1  tab2 PK ordkerkey 

ksh: ./cmpre.sh:  not found.
$
$ more cmpre.sh



$ more cmpre.sh
#!/usr/bash
#===========================
#Arguements Reading
#============================

schemaName="${1}"
firstTab= "${2}"
secondTab="${3}"
pKey="${4}"
orderBy="${5}"
db2 "set schema $schemaName"

#============================
#Execute Query as below
#CompareQuery "TAB1" "TAB2" "PK"
#============================

echo "db2 select count(*) from ${firTab} where ${pKey} NOT IN (select ${pKey} from ${secTab}) order by ${orderBy})"

Any one can tell why ksh has not recognized my script??

Maybe because your path to the interpreter is wrong!

One of the following commands will help you find the correct path in your system:

# which bash
/bin/bash
# whereis bash
bash: /bin/bash /usr/share/man/man1/bash.1.gz

Hello felipe,

yes that script work for me and executed .thanks for ur support.

Regards
kanaka