All Forums Database
18 Feb 2012
cast from decimal to float

I am trying to cast one decimal field to  float. I get an error "bad character" . I am not sure why ? is it not advisible to convert decimal to float type?

does anyone has any teradata manual link for sql reference for such kind of queries ? 

ulrich 816 posts Joined 09/09
19 Feb 2012

cast decimal to float shouldn't be a problem

 

select cast(123456789012345678 as decimal(18,0)) as dec_val,
              cast(dec_val as float) as float_val;
select cast(999999999999999999 as decimal(18,0)) as dec_val,
              cast(dec_val as float) as float_val;
select cast(123456789.012345678 as decimal(18,9)) as dec_val,
              cast(dec_val as float) as float_val;
select cast(999999999.999999999 as decimal(18,9)) as dec_val,
              cast(dec_val as float) as float_val;

 

work all fine.

Your error message is much more indicating that you do a char to float conversion and at least one row doesn't contain a float or decimal value...

Check show select of your query to see what you really access...

feel free to donate bitcoin:12kgAUHFUqvG2sQgaRBXFhCwyf9HXdkGud

24 Feb 2012

Hi Ulrich

Yeah you are right. I too tried to cast from decimal to float and it worked fine. As you mentioned, there might be one particular record creating the problem.

I am not able to figure out which insert is causing the problem. any way to find this record. What is the show select command that you mentioned. Cld u pls give me its syntax.

ulrich 816 posts Joined 09/09
24 Feb 2012

Just type

 

SHOW 

in front of your

SELECT ...

;

statement and submit the query. 

feel free to donate bitcoin:12kgAUHFUqvG2sQgaRBXFhCwyf9HXdkGud

You must sign in to leave a comment.