473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Leading Zeros

On a z/OS DB2 v8 platform, this refers to formatting a SMALLINT field as
two zoned-decimal (character) numerics, with a leading zero when there
is only one significant digit. I tried several different CAST formats
with no luck.

Is this possible?

Thanks,

Walter Rue
Oct 1 '08 #1
4 12298
On Oct 1, 3:16*am, WalterR <ws...@verizon.netwrote:
On a z/OS DB2 v8 platform, this refers to formatting a SMALLINT field as
two zoned-decimal (character) numerics, with a leading zero when there
is only one significant digit. *I tried several different CAST formats
with no luck.
Don't know if it works on your platform, nor if it fits you needs,
but ...

db2 "with T(n) as (values 11,2,63,4) select case when n < 10 then '0'
else '' end || char(n) from T"

/Lennart

Oct 1 '08 #2
Or, you can use RIGHT and DIGITS to do the same:

with o(n) as (values 11,2,63,4),
t(n) as (select cast(n as smallint) from o)
select right(digits(n),2) from t

-Chris
Oct 1 '08 #3
On Wed, 01 Oct 2008 02:16:36 +0100, WalterR <ws***@verizon.netwrote:
On a z/OS DB2 v8 platform, this refers to formatting a SMALLINT field as
two zoned-decimal (character) numerics, with a leading zero when there
is only one significant digit. I tried several different CAST formats
with no luck.

Is this possible?

Thanks,

Walter Rue
SELECT RIGHT(DIGITS(CAST(1 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1

UNION ALL

SELECT RIGHT(DIGITS(CAST(4 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1

UNION ALL

SELECT RIGHT(DIGITS(CAST(16 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1;

I
-----
01
04
16
Cheers,

Dave.
Oct 1 '08 #4
Dave Hughes wrote:
On Wed, 01 Oct 2008 02:16:36 +0100, WalterR <ws***@verizon.netwrote:
>On a z/OS DB2 v8 platform, this refers to formatting a SMALLINT field
as two zoned-decimal (character) numerics, with a leading zero when
there is only one significant digit. I tried several different CAST
formats with no luck.

Is this possible?

Thanks,

Walter Rue


SELECT RIGHT(DIGITS(CAST(1 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1

UNION ALL

SELECT RIGHT(DIGITS(CAST(4 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1

UNION ALL

SELECT RIGHT(DIGITS(CAST(16 AS SMALLINT)), 2) AS I
FROM SYSIBM.SYSDUMMY1;

I
-----
01
04
16
Cheers,

Dave.
I had been confidently looking for something built-in, but I guess I was
assuming it would have a more obvious name. Anyway, DIGITS is it.
Thanks also for the CASE solution. I tried both.

Walter Rue
Oct 4 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
1
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros...
6
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a...
5
by: OneDay | last post by:
I've got a field that has some old data with text in it, but all forward data will be a 3 digit number. But many of the numbers are still only 2 digits. I would like to force the leading zero in...
6
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function...
2
by: chris | last post by:
Hi, I have a simple ms access application that allows you to scan barcodes in to a form which stores them in the database. The barcodes are 6 digits in length e.g. 555666 but my handheld...
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
3
by: Jessica Tubbs | last post by:
Hi, I am trying to add leading zeros to a field but the zeros are not displying in the results. The code below will display the added zeros because I have a space at the beginning of my leading...
15
by: Deekay | last post by:
Is there a way to preserve possible leading zeros in a number even when it is passed as text? I have this code on a form which runs off a command button taking two values from user input, passing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.