title: Sql Join Tables Partial Join Concatenate Results?
body: <p>I have two tables. One has 2 columns - ID, tags.  The tags column is a comma delimited list of tag values.</p>
  
  <p>I the second table, there are also two columns.  One is a list of tags, each in it's own row, and the second column is a label for that tag.</p>
  
  <p>What I need to do is create an output query of each ID, with a semicolon delimited list of the tag labels, for each id that has that corresponding tag value in it's list.</p>
  
  <p>Here is a short example of the two tables:</p>
  
  <pre><code>Table1 - 
  ID---Tags
  1---tag1,tag2,tag3,tag6
  2---tag2,tag4,tag5
  3---tag3,tag8,tag9,tag10
  4---tag1,tag2,tag6
  5---tag1,tag4,tag5
  
  Table2 - 
  tagname---taglabel
  tag1--- Nice Name Tag1
  tag2--- Nice Name Tag2
  tag3--- Nice Name Tag3
  tag4--- Nice Name Tag4
  tag5--- Nice Name Tag5
  tag6--- Nice Name Tag6
  tag7--- Nice Name Tag7
  tag8--- Nice Name Tag8
  tag9--- Nice Name Tag9
  tag10--- Nice Name Tag10
  </code></pre>
  
  <p>Desired result set - </p>
  
  <pre><code>ID---TagsNames
  1---Nice Name Tag1,Nice Name Tag2,Nice Name Tag3,Nice Name Tag6
  2---Nice Name Tag2,Nice Name Tag4,Nice Name Tag5
  3---Nice Name Tag3,Nice Name Tag8,Nice Name Tag9,Nice Name Tag10
  4---Nice Name Tag1,Nice Name Tag2,Nice Name Tag6
  5---Nice Name Tag1,Nice Name Tag4,Nice Name Tag5
  </code></pre>
  
  <p>I tried to set up a query for an initial join, thinking I could take that results set and concatenate the rows, but I can't seem to get the partial join to work.  Here is that query:</p>
  
  <pre><code> SELECT gt.id as g
        ,gt.tags as tg
        ,tt.HitTagName as ht
        ,tt.termlabel as tl 
  FROM tblidtags gt (nolock)
  JOIN tbltaglabels tt (Nolock) ON gt.tg like '%' + tt.ht + '%'
  </code></pre>
  
  <p>Any suggestions are greatly appreciated!</p>