{"id":234,"date":"2012-06-01T16:24:37","date_gmt":"2012-06-01T16:24:37","guid":{"rendered":"http:\/\/www.eddiedillon.info\/?p=234"},"modified":"2012-06-01T16:24:37","modified_gmt":"2012-06-01T16:24:37","slug":"create-comma-delimited-string-from-multiple-tables-in-sql","status":"publish","type":"post","link":"https:\/\/www.eddiedillon.info\/?p=234","title":{"rendered":"Create Comma delimited string from multiple tables in SQL"},"content":{"rendered":"            <script type=\"text\/javascript\" src=\"https:\/\/www.eddiedillon.info\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushSql.js\"><\/script>\n<p>I recently had to create a string of values from a multi table join in sql and I wasn&#8217;t sure how to accomplish this so I did some research and came across the SUBSTRING function in SQL server.  This function takes a select statement and then the length to begin with and the max length of the string you want to return.  I used 1000 just to be safe but my string wouldn&#8217;t ever be larger than that.  I also used the FOR XML to return the data as xml and pass that to the SUBSTRING fuction for parsing.  I have posted the code below, enjoy.<\/p>\n<p><pre class=\"brush: sql\">select SUBSTRING((\r\n  SELECT (&#039;,&#039; + Table1.Name)\r\n  FROM Table1 join\r\n  Table2 on Table2.SomeID = Table1.SomeID\r\n  FOR XML PATH(&#039;&#039;)\r\n  ), 2, 1000)<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had to create a string of values from a multi table join in sql and I wasn&#8217;t sure how to accomplish this so I did some research and came across the SUBSTRING function in SQL server. This function takes a select statement and then the length to begin with and the max length [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[60,61],"tags":[],"_links":{"self":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/234"}],"collection":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=234"}],"version-history":[{"count":2,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":236,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions\/236"}],"wp:attachment":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}