# Thread: urgent...convert from decimal to char for bit data

1. Registered User
Join Date
Jul 2002
Posts
86

## Unanswered: urgent...convert from decimal to char for bit data

Hi All,
I work with db2 v7.2 Aix, I have a problem with converting data from decimal to char for bit data as follow:
tab1 (col1) has a column type decimal and tab2(col2) has a column type char(8) for bit data, I want to update col2 with col1 so I need convert col1 to char(8) for bit data and then use update command, I appriciate if you shar your knowledge with me .

Thanks

2. Super Moderator
Join Date
Aug 2001
Location
UK
Posts
4,650

## Re: urgent...convert from decimal to char for bit data

What is the DECIMAL field specification ? Does it occupy less than 8 bytes ?

See if the following helps

--------------------------- Command entered ----------------------------
create table tab1(i int, j decimal(10,2) , k char(12) for bit data)
------------------------------------------------------------------------
create table tab1(i int, j decimal(10,2) , k char(12) for bit data)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
insert into tab1(i,j) values(1,5.9)
------------------------------------------------------------------------
insert into tab1(i,j) values(1,5.9)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
insert into tab1(i,j) values(2,5.76)
------------------------------------------------------------------------
insert into tab1(i,j) values(2,5.76)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
update tab1 set k=char(j) where i=1
------------------------------------------------------------------------
update tab1 set k=char(j) where i=1
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
select * from tab1
------------------------------------------------------------------------
select * from tab1

I J K
----------- ------------ ---------------------------
1 5.90 x'30303030303030352E393020'
2 5.76 -

2 record(s) selected.

Originally posted by David2002
Hi All,
I work with db2 v7.2 Aix, I have a problem with converting data from decimal to char for bit data as follow:
tab1 (col1) has a column type decimal and tab2(col2) has a column type char(8) for bit data, I want to update col2 with col1 so I need convert col1 to char(8) for bit data and then use update command, I appriciate if you shar your knowledge with me .

Thanks

3. Registered User
Join Date
Jul 2002
Posts
86

## Re: urgent...convert from decimal to char for bit data

Originally posted by sathyaram_s
What is the DECIMAL field specification ? Does it occupy less than 8 bytes ?

See if the following helps

--------------------------- Command entered ----------------------------
create table tab1(i int, j decimal(10,2) , k char(12) for bit data)
------------------------------------------------------------------------
create table tab1(i int, j decimal(10,2) , k char(12) for bit data)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
insert into tab1(i,j) values(1,5.9)
------------------------------------------------------------------------
insert into tab1(i,j) values(1,5.9)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
insert into tab1(i,j) values(2,5.76)
------------------------------------------------------------------------
insert into tab1(i,j) values(2,5.76)
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
update tab1 set k=char(j) where i=1
------------------------------------------------------------------------
update tab1 set k=char(j) where i=1
DB20000I The SQL command completed successfully.

--------------------------- Command entered ----------------------------
select * from tab1
------------------------------------------------------------------------
select * from tab1

I J K
----------- ------------ ---------------------------
1 5.90 x'30303030303030352E393020'
2 5.76 -

2 record(s) selected.
you resolved my problem you are ''ROCK" thank you so much

4. Super Moderator
Join Date
Aug 2001
Location
UK
Posts
4,650

## Re: urgent...convert from decimal to char for bit data

decimal(10,2) and char(12) was just a coincidence and not 10+2 ...

If you define decimal(x,y) then define char no less than char(x+1)
(This +1 is to accomodate the decimal point ...

Cheers

Sathyaram

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•