Question

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
Was it helpful?

Solution

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

OTHER TIPS

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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top