|
|
Archives of the TeradataForum
Message Posted: Thu, 10 Aug 2006 @ 09:53:02 GMT
Subj: | | Re: Casting Char to Decimal |
|
From: | | McCall, Glenn David |
| I have a field defined as Char but i need to do some calculations on that field, For that i am trying to convert Char to Decimal using CAST
function, but it is not working. Could anyone please give me a solution for this. | |
This is one of those you need to supply more information things...
For example, what is the error message if any? What is the data you are using? How are you writing the cast? What is the data type of the
field? Does it work in bteq or queryman?
If you want help from the list, you should try and provide as much of this type of information as you can. Otherwise you might as well say, I'm
doing something, but it doesn't work, please help.
For what it is worth, the following does work in both queryman and bteq.
create table gmc_decimal (
c1 varchar (20),
c2 varchar (20)
);
insert into gmc_decimal values ('1.23', '10.67');
insert into gmc_decimal values ('3.14', '2.5');
select c1, c2, cast (c1 as decimal (10,2)) as d1, cast (c2 as decimal
(10,2)) as d2, d1+d2, d1*d2
from gmc_decimal
which produces:
c1 c2 d1 d2 (d1+d2) (d1*d2)
3.14 2.5 3.14 2.50 5.64 7.8500
1.23 10.67 1.23 10.67 11.90 13.1241
^^Character^^ ^^^Decimal^^^ ^^^Arithmetic^^^
Glenn Mc
| |