Reputation: 11
I'm hoping to get some help with this SQL statement.
RUNSQL_X SQL('UPDATE mylib/myfile SET N53DSC = ''' *CAT &TEXT *CAT ''' where ''' *CAT + &N53GIDCHAR *CAT ''' = ''' *CAT &CHARID# *CAT ''')') COMMIT(*NONE)
When I run this inside my CLLE
program, I get the following message:
Token ) was not valid. Valid tokens: OR USE SKIP WAIT WITH.
Any help would be greatly appreciated.
Upvotes: 1
Views: 3469
Reputation: 23783
First off...take care using dyamic statements like this as they can open up the possibility of SQL injection attacks. It'd be safer to use a static SQL statement inside of RPGLE.
But if you must use CLLE... try the following:
dcl "e type(*CHAR) len(1) value ('''')
dcl &stmt type(*char) len(512)
chgvar var(&stmt) value('UPDATE mylib/myfile set n53dsc = ' +
*CAT "e *CAT &TEXT *CAT "e +
*CAT 'where ' *CAT &N53GIDCHAR *CAT '=' +
*CAT "e *CAT &CHARID# *CAT "e)
dmpclpgm
runsql_x SQL(&stmt) COMMIT(*NONE)
EDIT
Based on your comment. I'd liek to point out that reading one record at a time and updating (with SQL) is a poor use of SQL.
SQL is designed & optimised for set a time operations...
I think the following would accomplish what you are trying to do..(not sure exactly what fields are in which tables)
update mylib/myfile
set n53dsc = <TEXT>
where n53gidchar in (select n53gidchar from mylib/otherfile)
and n53gidchar = charid#
Upvotes: 1