Using SUBSTR with interactive SQL

220 pts.
Tags:
AS/400
SQL
I am trying to change part of a field using the substring command in interactive SQL. To do this I entered the following:

UPDATE LIBRARY/FILE_NAME SET SUBSTR(FIELD_NAME1,194,4) = 'XXXXX' WHERE FIELD_NAME2 = 99999 


I get the error token ( was not valid. Valid tokens: = .' Obviously there is a syntax error but O cannot figure it out.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Unless something has changed SUBSTR cannot be used as the target of set. It can however be used as part of the expression setting the variable. Try:

UPDATE LIBRARY/FILE_NAME SET FIELD_NAME1 = SUBSTR(FIELD_NAME1,1,193) || 'XXXX' || SUBSTR(FIELD_NAME1,198) WHERE FIELD_NAME2 = 99999

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Victorycr3027
    I had to change last 3 char of a 6 char field. I used following command using example from Michael and it worked. I had to change all records so I didnot use any where condition.
    UPDATE LIBRARY/FILE_NAME   SET field_name = SUBSTR(field_name, 1, 3) || 'EDI' 

    25 pointsBadges:
    report
  • GregManzo
    Yep, that's right. In RPG the %subst() BIF can be used as the result of an expression but SQL doesn't support that.
    1,720 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: