[Info-ingres] add leading zero in sql

Martin Bowes martin.bowes at ndph.ox.ac.uk
Mon Apr 26 07:50:58 UTC 2021


Hi Allen,

Nothing slick…

select sales_oi_number = varchar(order_number) + right('00' + item_number, 2) from stuff


From: Allan Biggs <allanb4 at iname.com>
Sent: 23 April 2021 09:29
To: Ingres lists <info-ingres at lists.planetingres.org>
Subject: [Info-ingres] add leading zero in sql


Hopefully someone can put me out of my misery

in the following item number can be 1 to 99 always 2 digits

I want to end up with a 6 digit order number and a 2 digit , with a leading zero if necessary item number in sales_oi_number

select

sales_oi_number   = varchar(order_number)  + varchar(item_number)

from xxxxx

order_number and item_number are integers

for order_number 123456 and item_number 22 sales_oi_number would be '12345622'

for order_number 123456 and item_number 2 how do I get '12345602' and not '1234562'

Is there a slick of doing this - I can imagine a tortuous route of  left() right() etc etc

thanks
Allan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.planetingres.org/pipermail/info-ingres/attachments/20210426/d5c5fd2d/attachment.html>


More information about the Info-ingres mailing list