Need help with return code 1...

Hi Guys,,

I am having a unix script which is running the DB2 Insert command.
For the insert command, there were no records to be updated.

SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table. SQLSTATE=02000
+ + echo 1
STAGE_RC=1
+ [[ 1 != 0 ]]

Because of this, it is returning return code as 1.
My script will work, only if this part of the script is successful as u can see the in the code above.

all 1 in the codes are return code.

is it because of the DB2 insert statement or is it due to something else..When will the return code be 1??

I found your post confusing. What command do you run that gives you the exit code of 1? The output you showed above is an unsuccessful fetch/update/delete because the table was empty. I would expect a 1 returned from such a script.

sorry guys i inserted the script but somehow the log file got pasted..

thanks otheus,, so in the case of no rows found for update or insert,, the return code willl be 1.. rite??

But the same script is running fine, for the other family codes which also shares the same scenario.. (No rows found for update or insert)

could you please explain me that?

Like I said, I would expect the return code from such a command to be 1. But since you did not post the command, I cannot possibly know. I probably wouldn't know anyway, since I have very little experience with DB2. I recommend you repost in the "Database" or "AIX" forums with "such-and-such command sometimes returns 1 on failure".

This is the piece of code causing trouble.. otheus..

db2 "insert into table \
(col,,,,\
) \
select * from tab1 a, tab2 b where\
a.id=b.id \
with ur"

STAGESUM_RC=`echo $?`
if [[ $STAGESUM_RC != "0" ]] ; then
ReturntoParent $STAGESUM_RC "Error in Insert Fact Stage_Sum"
fi
db2 "commit"

I doubt this will change anything, but it's better to change the first line to:

STAGESUM_RC=$?

Still, the db2 error indicates that your select * is failing. Is it possible that select sometimes returns an empty result?