This is the first time I ran into a situation where I needed to Join two tables (one with a varchar field and one with a
varchar field that contains pipe delimited data) so I decided to post it for other who may not know you can do this. Below is a simplified example with solution of getting all rows of the first table whos values are contained in the pipe delimited field of the second table. This is really simple to do and you don’t even have to use any User-Defined Functions or Cursors to do it. And I’m sure that not all of you who may read this know that you can use LIKE in a JOIN.
SELECT City FROM Table1 JOIN Table2 ON Table2.CityList LIKE '%' + Table1.City + '%'
Table1 Sample Data
- West Bend
Table2 Sample Data
West Bend Kewaskum
- 01 Jul 2020
- 06 Apr 2020
- 11 Mar 2020
- 15 Feb 2020
- 02 Jan 2020
Recent on Build5Nines.com
Latest Cloud News: Azure Dev Guide eBook, xCloud, Cloud Shell + VNet and more! (August 11, 2020 – Build5Nines Weekly)11 Aug 2020
- 07 Aug 2020
Latest Cloud News: Azure Cloud Shell Tips, Azure Sphere, Microsoft acquire TikTok, NVidia acquire ARM, and more! (August 6, 2020 – Build5Nines Weekly)06 Aug 2020
- 01 Aug 2020
This site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. We also participates in affiliate programs with Udemy, and other sites. This site is compensated for referring traffic and business to these companies.