how to get SQLCODE ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to get SQLCODE ?
# 1  
Old 10-14-2008
how to get SQLCODE ?

Suppose I am executing a sql query thru shell script.
DB : IBM DB2

Quote:
db2 "select * from table1 with ur"
If none of the rows are fetched, I will be getting the sql code as 100
If rows > 0 are fetched, I will be getting the sqlcode as 0

Can any one help me how to get this SQL code in unix shell script (in KSH)

Krishnakanth
# 2  
Old 10-15-2008
I don't know the syntax with "WITH", only with "WHERE", etc.
If you db2 SQL query finds at least 1 row, the returncode of your command will be 0, if not it is 1 or at least > 0.
So you can work with testing $? or parse whatever SQL code you are getting by putting your command into a variable maybe like for example
Code:
VAR=`db2 "select something from sometable..."`

Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

return DB2 SQLCODE

Hello All, I have 2 shell scripts. script1.sh script2.sh script1.sh call script2.sh script2 will connect to DB2 database and execute a insert statement. I am capturing the return value of insert statement in an variable called SQLCODE. I want to return this SQLCODE to the calling script... (0 Replies)
Discussion started by: kjaisan
0 Replies
Login or Register to Ask a Question