• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Change a Substring with SQL

    April 5, 2006 Hey, Ted

    I am trying to change part of a character field with an SQL UPDATE command. However, my SQL command gives me an invalid token error at the opening parenthesis of SUBSTR in the SET statement. Is there a rule that you can’t use SUBSTR in a SET statement? If so, do you have a workaround?

    –Dennis

    What you’re trying to do is reasonable, Dennis. After all, RPG and CL let you change part of a character field using their %SUBST and %SST functions. But SQL is different.

    For the benefit of other readers, here is the SQL command Dennis sent to me.

    update library/file 
       set substr(rpc,1,3) = char(comno)
     where comno in (015,016) and substr(rpc,1,3) = ' '
    

    Dennis wants to replace the first three characters of the RPC field with whatever is in COMNO, but only if those characters are blank and only for records in companies 015 and 016. The solution is to replace the entire field, not just part of it, by selecting the parts you wish to keep and replacing the part you wish to update, like this:

    update library/file
       set rpc = char(comno) || substr(rpc,4)
     where comno in (015,016) and substr(rpc,1,3) = ' '
    

    In this example, the new value of RPC is the three company number digits concatenated to whatever is in positions four and following.

    Thanks for the question, Dennis. This is a handy technique to know.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    California Software:  Migrate iSeries apps to Windows, Linux, or Unix
    Computer Keyes:  Rapidly convert *SCS printer files into black and white or full color PDF documents
    Bug Busters Software Engineering:  Quality software solutions for the iSeries since 1988

    Doug Fulmer to Leave IBM for Clear Technologies The Lowdown on S/36 and S/38 Compilers in i5/OS V5R5

    Leave a Reply Cancel reply

Volume 6, Number 14 -- April 5, 2006
THIS ISSUE SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
TurboGorilla

Table of Contents

  • Avoiding the Green Screen of Death in RPG Programs
  • Change a Substring with SQL
  • Admin Alert: Protecting Your System from Critical Storage Errors

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle