
October 1st, 2008, 02:25 AM
| | | 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 | 
October 1st, 2008, 06:15 AM
| | | Re: Leading Zeros
On Oct 1, 3:16*am, WalterR <ws...@verizon.netwrote: Quote:
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 | 
October 1st, 2008, 04:45 PM
| | | Re: Leading Zeros
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 | 
October 1st, 2008, 05:25 PM
| | | Re: Leading Zeros
On Wed, 01 Oct 2008 02:16:36 +0100, WalterR <wsrue@verizon.netwrote: Quote:
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. | 
October 4th, 2008, 09:35 PM
| | | Re: Leading Zeros
Dave Hughes wrote: Quote:
On Wed, 01 Oct 2008 02:16:36 +0100, WalterR <wsrue@verizon.netwrote:
> Quote:
>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 |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|