store in char column getting from decimal column in db2 -


create table test1 (no decimal(4,2) ,name char(10))

create table test2 (no char(1) ,name char(10))

insert test1 values(1,'aa') insert test1 values(2,'ab') insert test1 values(3,'ac') insert test1 values(4,'ad') insert test1 values(null,'ad')

insert test2 (no,name) (select cast(no char(1)),name test1)

not working. clues.

thanks.

are intentionally using char rather varchar? varchar won't pad text spaces.

when run insert, following error:

insert test2 (no,name) (select cast(no char(1)),name test1) sql0445w  value "1.00  " has been truncated.  sqlstate=01004 

the actual insert works me, suggests need char(4) or varchar(4) rather char(1).

if want automatically drop digits after decimal, cast values bigint first:

insert test2 (no,name) (   select      cast(cast(no bigint) char(1)),     name   test1 ) 

note still run truncation issues values 10 or -1.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -