{"id":553,"date":"2012-09-24T16:29:52","date_gmt":"2012-09-24T11:29:52","guid":{"rendered":"http:\/\/www.esearing.com\/v2010\/?p=553"},"modified":"2012-09-24T16:29:52","modified_gmt":"2012-09-24T11:29:52","slug":"sql-rows-to-column","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2012\/09\/sql-rows-to-column\/","title":{"rendered":"SQL Rows to Column"},"content":{"rendered":"<p>I had an interesting challenge this week where I needed to turn rows of email addresses into a crosstab or a single column so I could use it to send out emails. I had to do this at a grouped level for different companies and there may be from 1-5 different email addresses. Here is the SQL solution.<\/p>\n<p><code><br \/>\nSELECT DISTINCT company, C.rep_email<br \/>\nFROM #emails<br \/>\n<strong>CROSS APPLY<\/strong><br \/>\n(<br \/>\nSELECT [rep_email] + ';' -- semi colon separator<br \/>\nFROM ###emails# E<br \/>\nWHERE E.company=#emails.company<br \/>\nFOR XML PATH('')<br \/>\n) C(rep_email)<br \/>\n<\/code><\/p>\n<p>Then I use coldfusion to create a mail link but you can use any tool that allows you to format the mail to parameter with the new rep_email values.<br \/>\nI looped through each company and created a mail link for my app, but could have sent out all the emails at once if I had desired. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had an interesting challenge this week where I needed to turn rows of email addresses into a crosstab or a single column so I could use it to send out emails. I had to do this at a grouped &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2012\/09\/sql-rows-to-column\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,24,14],"tags":[41,40,42],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-code","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql","tag-cross-apply","tag-crosstab","tag-rows-to-column"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=553"}],"version-history":[{"count":2,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":555,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/553\/revisions\/555"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}