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
 General SQL Server Forums
 New to SQL Server Programming
 joining two tables on idnum with 2 different data

Author  Topic 

Trininole
Yak Posting Veteran

83 Posts

Posted - 2010-09-15 : 10:21:48
How do i join two different tables with the same column name that have different data types? For example how would i join two tables with the column name "idnum" with one table having the column name as a numeric data type and the other table having the column name as an integer data type?

Roger DeFour

kashyap.2000
Starting Member

22 Posts

Posted - 2010-09-15 : 10:31:15
Convert one of the columns to other data type while joining. for instance .... select * from table1 t1 join table2 t2 on (t1.column1=cast(t2.column as integer))
Go to Top of Page

rohitvishwakarma
Posting Yak Master

232 Posts

Posted - 2010-09-15 : 10:47:44
If it is SQL Server 2008
No need to CAST. just write the JOIN as usual without any casting i.e.

SELECT * FROM Table1 INNER JOIN Tabl2 ON Table1.common_column = Table2.common_column

I have tested it with the Int,Varchar & Int,Numeric combinations and it works fine.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-15 : 10:51:48
oye

That's because SQL Server (and the development team) in their infinite "wisdom" do an internal conversion...

And it's NOT True trhat you won't run into problems..especially with varchar = int



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -