views:

1496

answers:

2

I've got an AIX batch job that uses isql to execute a stored procedure in Sybase. The stored procedure is returning an error code under certain conditions. I would like for isql to pass that return code to the AIX script.

Can I capture the the stored proc's return code within isql, or do I have to write an output file of some kind and have my AIX script check that?

Here's what the isql command looks like. It's running inside a Korn shell script.

isql -D$database -S$server -U$userId -P$password << EOF
EXEC MY_STORED_PROC $AN_INPUT_PARAMETER
go
EOF
+1  A: 

If I remember correctly, the $? is set to the command return value. Add something like this after the EOF line:


if [[ $? != 0 ]]; then
    print "stored procedure failed"
    exit
fi
Nikolai N Fetissov
Thanks for the post. I didn't know about $?. That gets me halfway there. isql is still returning 0 even though the stored proc is returning a different value. Any idea how I can get isql to recognize the stored proc's return value?
John M Gant
Hmm, my best bet would be to play with the error levels (-m option) and/or redirect isql output to a file and do a quick sed/awk on it.
Nikolai N Fetissov
A: 

Is this what you wanted to achieve?

isql -D$database -S$server -U$userId -P$password << EOF | grep RETVAL | awk -F"=" '{print $2}' | read value
declare @retval int
EXEC @retval = MY_STORED_PROC $AN_INPUT_PARAMETER
SELECT "RETVAL=" + convert(varchar, @retval)
go
EOF

echo "Procedure returned: $value"
B0rG