Hello Everyone,
I'm having a wee bit of a problem. I would like to pass a DB2 query to a variable and then using that variable to perform a 'For' loop.
For example....
Code:
tempfile1=`db2 -x "select cast(OBJECT_ID as integer) from $temp_table where SEQUENCE_NO = $sequence_no"`
for id in ${tempfile1}
do
statename=`db2 -x "select STATE_NAME from $temp_table where object_id = $id"`
domain_name=`db2 -x "select domain_name from $temp_table where object_id = $id"`
echo "ID = [$id]"
echo "State = [$statename]"
echo "Domain = [$domain_name]"
done
The problem is when I run this if there are multiple object_id's with the same value but not the same state_name then when it's passed through an echo it looks like this....
Code:
ID = [5132]
State = [State1 State2]
Domain = [Domain1 Domain2]
ID = [5146]
State = [State1]
Domain = [Domain1]
ID = [5156]
State = [State1 State2]
Domain = [Domain1 Domain2]
ID = [5132]
State = [State1 State2]
Domain = [Domain1 Domain2]
ID = [5156]
State = [State1 State2]
Domain = [Domain1 Domain2]
However I would like it to look like this...
Code:
ID = [5132]
State = [State1]
Domain = [Domain1]
ID = [5146]
State = [State1]
Domain = [Domain1]
ID = [5156]
State = [State1]
Domain = [Domain1]
ID = [5132]
State = [State2]
Domain = [Domain2]
ID = [5156]
State = [State2]
Domain = [Domain2]
Would someone be able to see what I'm doing wrong.
Thanks in advance.....




