Search code examples
sqlibm-midrangedb2-400

Need to add 1 pos. to the substring in this SQL


This sql is working but the second substring, is the order num. For these we need to add a '0' at the end, to make it 8 pos now. Not sure how to do this in SQL.

SELECT                                                             
  ALL       SUBSTR(UANOTL,1,4) AS CODE1, SUBSTR(UANOTL,5,7) AS ORDER#, 
            UAATHN, UANOTD                                                 
  FROM      ASTDTA.NOTEH1 T01                                      
  WHERE     SUBSTR(UANOTL,1,4) = 'REM '                            

Solution

  • You need the concatenation operator:

    SELECT ALL 
      SUBSTR(UANOTL,1,4) AS CODE1, 
      SUBSTR(UANOTL,5,7) || '0' AS ORDER#, 
      UAATHN, UANOTD
    FROM ASTDTA.NOTEH1 T01
    WHERE SUBSTR(UANOTL,1,4) = 'REM '