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
 Join using wild card character

Author  Topic 

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2010-10-06 : 16:34:32
Hi Guys,
A list of StoreNames are passed which will be loaded into a table variable @TestTable2. I have a lookup table in the db that has the StoreNames in our example @TestTable1

DECLARE @testTable1 TABLE (
StoreName varchar(128)
)

INSERT @testTable1 (StoreName)
Select 'Rockville Pike Store1'
union
Select 'Wheaton Store2'
union
Select 'DC Store9'

DECLARE @testTable2 TABLE (
StoreName varchar(128)
)

INSERT @testTable2 (StoreClosed)
Select 'Pike Store1'
union
Select 'Store2'


TestTable2 will have partial StoreName... is there a way to join these two tables using wild card character so that I can get the StoreName from Table1 for StoreNames in Table2?

So I should have something like this:

Table2Name Table1Name
-------------------------------------------
PikeStore1 Rockville Pike Store1
Store2 Wheaton Store2

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-06 : 16:38:52
Yes you can use JOIN for this with LIKE and %, however performance will suffer.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2010-10-06 : 16:44:39
thanks tkizer... that works for now.
Go to Top of Page
   

- Advertisement -