How to concatenate string without LOOP in SQL Server?


Before i discover this method “concatenate string without LOOP in SQL Server“. I usually will use cursor to loop and then concatenate string one by one … (Argghh… BORING!), Let me show you with an example.

concatenate string without LOOP in SQL Server




1. Create Table Variable and Insert Few lines Of Data

2. NOT Elegant Method, Concatenate String With Loop In SQL Server


Well, I guess you know of this method, nothing proud off ;). This is the usual way that all of us will do.

3. Elegant Method! Concatenate String WithOUT Loop In SQL Server


This is the method you need to STICK in your head and forget about the loop. 🙂 Today I accidentally write a mistake concatenate string statement and found this magic line!!!

Both return the same output BUT the 2nd T-SQL is much shorter!!!
So Why you need a LOOP to achieve this!!?? 🙂




JOIN OUR NEWSLETTER
In case you want to get any future post please allowed us deliver new posts direct into your inbox Or follow us on
We hate spam. Your email address will not be sold or shared with anyone else.