Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 1st, 2008, 02:25 AM
WalterR
Guest
 
Posts: n/a
Default 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
  #2  
Old October 1st, 2008, 06:15 AM
Lennart
Guest
 
Posts: n/a
Default 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

  #3  
Old October 1st, 2008, 04:45 PM
ChrisC
Guest
 
Posts: n/a
Default 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
  #4  
Old October 1st, 2008, 05:25 PM
Dave Hughes
Guest
 
Posts: n/a
Default 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.
  #5  
Old October 4th, 2008, 09:35 PM
WalterR
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles