Midrange News for the IBM i Community


Posted by: renojim
concat with leading zero's
has no ratings.
Published: 11 Feb 2014
Revised: 11 Feb 2014 - 1203 days ago
Last viewed on: 29 May 2017 (2129 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

concat with leading zero's Published by: renojim on 11 Feb 2014 view comments(3)

Anybody know how to return two integers in an sql statement, preserving any leading zeros in the second integer?

So if the fields are 1,0 and 4,0 respectively, and the values are

1  and 0002

I can select concat(firstfield, secondfield) (or '||', if you prefer), and get

10002.

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: DaleB
Premium member *
Reading, PA
Comment on: concat with leading zero's
Posted: 3 years 3 months 16 days 18 hours 52 minutes ago

DIGITS function will do it.

SELECT CONCAT(DIGITS(firstfield), DIGITS(secondfield))

It uses absolute value of the number, so if your values can ever be negative, you'll want some sort of CASE to deal with the sign.

Posted by: tdaly
Premium member *
Comment on: concat with leading zero's
Posted: 3 years 3 months 16 days 18 hours 37 minutes ago
select ((fld1 * 10000) + fld2) as myfld
Posted by: renojim
Premium member *
Comment on: concat with leading zero's
Posted: 3 years 3 months 16 days 18 hours 26 minutes ago

Excellent!! Thanks.