Posts

Showing posts from February, 2017

TSQL - String Concatenation

On current project, I ran into a scenario where I needed to concatenate a series of rows into a single string value.  Nothing major, just concatenate them with a delimiter and return the result.  As all of us Microsoft SQL developer's know and deal with is the lack of a SQL supported function that is able to assist us in this "minor" feature. As this is my knowledge dump for techniques and other methods used for the various platforms, here we go: Construct: The first step is to identify what information you want, the basic's of query design.   SELECT Email FROM Contacts Group By Email Group by is conditional, depending on your situation and how you organize your referential integrity. Stage Next, lets build our environment, not the SProc just the supporting actors in the process. declare @email varchar(max) = '' SELECT @email += Email + ', ' FROM Contacts Group By Email This simply concatenates each of