Search code examples
sqlcastingteradatateradata-sql-assistant

Teradata using CAST in a JOIN statement


I'm trying to add some fields to an existing report that runs just fine. To add these fields, I need to join to another table. The problem is the field is a different type on each table

Table A / FieldA = Varchar (20)
Table B / FieldB = Decimal (19,0)

This is the join I have:

inner join TableA ta on ta.FieldA = b.FieldB 

With this join, I get a SELECT Failed [3754] Precision error in FLOAT type constant or during implicit conversions.

I'm thinking I have to use a CAST statement like this:

inner join TableA ta on ta.FieldA = cast(b.FieldB as Varchar (20))

When I run the report now, I don't get any results and I'm expecting at least 1 row.

Any help with the inner join would be greatly appreciated. Thanks.


Solution

  • Instead of the cast, try:

    TO_CHAR(b.FieldB)