Error while using STRSQL

0 pts.
Tags:
AS/400
When I run the following command I get an error while using STRSQL. Is this a valid statement or am I losing my mind. select right(gmans, 5) from f0901 (This is the error I get) RIGHT in *LIBL type *N not found. If I use the "Left" command it works fine.
ASKED: September 15, 2005  3:53 PM
UPDATED: June 14, 2013  3:17 PM

Answer Wiki

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

There is no RIGHT function in SQL only a LEFT. Your best bet is to use a SUBSTR function if the field is an exact length to extract the last 6 positions

Example – Select SUBSTR(gmans,strpos,6)from f0901

where strpos is a numeric starting position.

=======================================================

Note that RIGHT() is a scalar function available in DB2 on iSeries as of V5R3.

Tom

========================================================

If you are at a OS Version that does NOT support RIGHT() then you can emulate it with the following:

<pre> select substr(trim(gmans), max(length(trim(gmans)) – 5, 1), 6) from f0901 </pre>

BigKat

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • PaulThomas
    Losing your mind :-) According to the "DB2 Universal Database for iSeries SQL Reference" LEFT is a Scalar Function, listed under Built-in Functions. There is no definition for RIGHT. So presumably RIGHT does not exist (as the error message suggests)
    0 pointsBadges:
    report
  • JPLamontre
    Don't presume, read the docs. this doc is available in PDF format in the ibm doc cdrom : ...InfoCenterinfodb2rbafzmst.pdf or on line Personnaly, I have a local copy of this 2-cd-intranet-site on my PC, it is a must !
    0 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following