Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 JOIN tables when column DATA TYPE differs

Author  Topic 

Cousboy
Starting Member

7 Posts

Posted - 2012-04-05 : 07:19:29
Hi,

I am having difficulty joining 2 tables in a SELECT statement where the datatypes of the 2 columns being joined are different.

An example of my SELECT statement is as follows.

-----------------------------
SELECT t1.column1, t2.column1
FROM table1 t1
JOIN table2 t2 ON (t1.column1 = t2.column1)
-----------------------------

t1.column1 is datatype CHAR(8)
t2.column1 is datatype VARCHAR(60)

I understand that there is an Implicit Conversion between these 2 datatypes and I have also tried a variety of CAST & CONVERT statements.

Please let me know if you need any further info. Any help would be greatly appreciated.

Many thanks

Cousboy

parody
Posting Yak Master

111 Posts

Posted - 2012-04-05 : 10:10:25
Are you suggesting the data conatined in these columns does not produce the output you expect when joined?

Do you have examples of the data in each table?
Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-04-09 : 07:56:30
Please post the DDL of your tables and some sample data.

Vinu Vijayan
Go to Top of Page
   

- Advertisement -