tsql - How to concatenate results in T-SQL into column? -


I am working on a query for which I should give results:

 | --name - - | --name | - | - Language-- | --Date - | | James | Hatfield | N, GB, FR | 2011-01-01 | | Lars | Ulrich | GB, FR, CA. 2011-01-01 |  

But my selection is set as rows:

 | James | Hatfield | En | 2011-01-01 | | James | Hatfield | GB 2011-01-01 | | James | Hatfield | Fr | 2011-01-01 | | Lars | Ulrich | GB 2011-01-01 | | Lars | Ulrich | Fr | 2011-01-01 | | Lars | Ulrich | Ca | 2011-01-01 |  

Which best method advises you to change the set of results in values ​​grouped in comma 'grouped in comma to fly?' I've found that implementing a cross can work but people say that this method is very conservative. An additional DB has too much data. Thank you in advance, Regards, Adrian

Here is the best combination method, This will not extend to other XML methods such as special characters:

  - Integration for XMLand; Destroy the control / encoded four expansions "& amp; & lt; & gt;" Set NOOcount ON; Put your + your values ​​(yourself 1) into your accessible values ​​(2,2, 'B & L; & amp; B; ) Your Talebl value (3.2, enter the 'AAA') @ your Talebl value (4,3, '& lt; br & gt; Enter') your values ​​(5, 3, A and Z) Insert set Nocount off SELECT t1.HeaderValue, CHILDVALUE for STUFF ((T SELECT ',' + t2.ChildValue fROM @YourTable T 2 WHERE t1.HeaderValue = t2.HeaderValue oRDER 2. XML PATH ( '', TYPE) Kvalue ( 'K', 'Varchar (max)), 1,2' ') your baby hair value through T-1 through T-1 group. T1.HeaderValue   

Output:

  Header Value Child Value ----------- --------------- 1 CCC 2 AAA, B & Lt; & gt; b 3 & lt; br & gt;, A & amp; Z (3 row)    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -