Page 1 of 1

using SQL in routine

Posted: Fri Nov 24, 2017 10:48 am
by India2000
Hi,

I want to use SQL statement :

select colum1 from schema.table where colum2='abc'


Cmd = "db2 " : "'connect to pdw_dev user pdw using Db2dba1'"

Call DSExecute('UNIX',Cmd,Output,Status)

Cmd = "db2 -x " : "'select colum1 from schema.table where colum2='abc' '"

Call DSExecute('UNIX',Cmd,Output1,Status)




This routine doesn't return anything from the SQL. Can anyone help me with the syntax? Thanks

Posted: Fri Nov 24, 2017 11:24 am
by chulett
How about starting by checking the status of your calls and logging that? I'd also include logging the output so you have some clue what is going on while you get this working.

Posted: Fri Nov 24, 2017 12:36 pm
by India2000
db2 -x 'select colum1 from schema.table where colum2='abc' '

DSLogInfo called from :0

Result= SQL0206N "abc" is not valid in the context where its used
SQLSTATE=42703

Posted: Fri Nov 24, 2017 4:01 pm
by chulett
And... solved?

If not, did you look up the error or have any thoughts on what the issue might be? What happens when you run that same statement at the command line as the user that the job is running under? Get it running there before throwing it into the routine...

Posted: Sun Nov 26, 2017 10:42 pm
by India2000
no, not.
if I use the DB2 commandline processor to run the query it returns the rows.

This command works for the numeric constant values like but not for character value.
db2 -x 'select colum1 from schema.table where colum2='1123'

Posted: Mon Nov 27, 2017 1:49 am
by ray.wurlod
You can't (successfully) enclose single quote characters in single quotes.

Posted: Mon Nov 27, 2017 8:23 am
by chulett
... or (successfully) use mismatched quotes.

Posted: Mon Nov 27, 2017 9:46 am
by sriven786
Try running with Double quotes

db2 -x "select colum1 from schema.table where colum2='abc'"