June 23, 2010 at 12:59 pm
Hi ,
I would like to join two tables A and B. Table A has a column Drug and table B has column drug1. But there is no matching name in both the columns.
TABA TabB
Drug Drug1
acid 123acidtc
base 987basegt
arythom 98arythomgt
If you observe in the above example you can see Both the columns match if you use like condtions.
Can you help me out how to use like condtions in this kind of situation.
June 23, 2010 at 2:15 pm
Try something like this:select * from tableA
join tableB on tableA.drug like '%' + tableB.drug1 + '%'
I think this is the correct syntax. (Someone correct me if I'm wrong.)
Also, keep in mind that this may not give you a one-to-one table join.
Hope this helps!
+--------------------------------------------------------------------------------------+
Check out my blog at https://pianorayk.wordpress.com/
June 23, 2010 at 7:57 pm
Ray K (6/23/2010)
Try something like this:select * from tableA
join tableB on tableA.drug like '%' + tableB.drug1 + '%'
I think this is the correct syntax. (Someone correct me if I'm wrong.)
Also, keep in mind that this may not give you a one-to-one table join.
Hope this helps!
Looks good to me and you're also correct about it likely (pun on words, sorry) not producing a one-to-one join.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2010 at 8:05 pm
You're also likely (continuing the pun) to see some pretty poor performance - with the leading wildcard, you won't be able to utilize an index.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply