SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Inner Join on Varchar fields
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ciupaz
Posting Yak Master

Italy
232 Posts

Posted - 01/10/2013 :  08:08:46  Show Profile  Reply with Quote
Hello all,
I have 2 tables with a Varchar(100) fields, something like these:


TableA
TableA_ID - Value - Description - Value2
1 - 23 - 'City1 Gr. 1' - 300
2 - 25 - 'City1 Gr. 2' - 340
3 - 33 - 'City2 Gr. 1' - 320
4 - 13 - 'City3 Gr. 1' - 308




TableB
TableB_ID - Value - Description - Value2
1 - 63 - 'City1 Gr. 1' - 500
2 - 75 - 'City1 Gr. 2' - 540
3 - 63 - 'City2 Gr. 1' - 520
4 - 83 - 'City3 Gr. 1' - 508

Is it possible join them with the varchar fields?

Thanks in advance.


Luigi

PS
I'm using SQL Server 2008 R2

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/10/2013 :  08:58:47  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Yes.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Ciupaz
Posting Yak Master

Italy
232 Posts

Posted - 01/10/2013 :  09:26:25  Show Profile  Reply with Quote
It does not work, maybe for culture o accent impostations?

Luigi
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4604 Posts

Posted - 01/10/2013 :  13:26:28  Show Profile  Reply with Quote
Are you saying the varchar COLUMNs have different collations?
Go to Top of Page

wholesalenfljerseyssale
Starting Member

9 Posts

Posted - 01/11/2013 :  01:17:14  Show Profile  Reply with Quote
unspammed
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/11/2013 :  03:02:48  Show Profile  Reply with Quote
quote:
Originally posted by Ciupaz

It does not work, maybe for culture o accent impostations?

Luigi


first check if contents are exactly same without any additional non printable characters

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Ciupaz
Posting Yak Master

Italy
232 Posts

Posted - 01/11/2013 :  03:06:09  Show Profile  Reply with Quote
Yes, they have, I think, differente collations.

Luigi
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/11/2013 :  03:09:46  Show Profile  Reply with Quote
then overide them using COLLATE in join like

SELECT *
FROM tablA a
JOIN TableB b
ON b.Description COLLATE database_default = a.Description COLLATE database_default


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Ciupaz
Posting Yak Master

Italy
232 Posts

Posted - 01/11/2013 :  03:33:32  Show Profile  Reply with Quote
This works. Thank you very much Visakh.

Luigi
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/11/2013 :  03:37:38  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000