Re: Convert char to smallint (within SQL statement)
Posted in 1998
Topics: SQL Development & Query Writing, Data Types & Schema Design
Hi,
SoftTeam Blas Catherine wrote in message <714rii$rof$1@news.xmission.com>...
>
>I have two fields in two different tables on which I want to make a join
>in my select statement. The problem is that one of two is a char(8) and
>the other one is a smallint.
>
>Example :
>
>field1 : smallint
>field2 : char(8)
>
>select * from Table1,Table2 where field1 = field2 ...>
>
>How can I make the conversion.
>I can't modify the data type in my database.
If I understand your question correctly, "+0" (plus zero) can be appended to
the char field in the where clause to force the engine to convert the field
to numeric for the life of the select. e.g.
select * from Table1,Table2 where field1 = field2+0
However, you need to make sure that all rows returned are valid numerics by
placing a filter on the Select
You will also have to keep an eye on the impact this temporary conversion
has on resources.
Hope this helps.
Andy C.