TSQL to Concatenate Subquery Row Values into a Column Value


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. ( SELECT SA.AttributeName + ':' + SAV.AttributeValue + ', <br>'
  2. FROM Core.ProductAttributeValue PAV
  3. JOIN Core.AttributeValue SAV ON SAV.AttributeValueId = PAV.AttributeValueId
  4. JOIN Core.Attribute SA ON SA.AttributeID = SAV.AttributeId
  5. WHERE PAV.ProductID = P.ProductId AND PAV.Version = P.Version
  6. FOR XML PATH('')) AS Attributes,
  7.  
  8. --Simple Version
  9. (
  10. SELECT T.ColToConcat + ","
  11. FROM SubqueryTable T
  12. WHERE T.Id = MainQuery.Id
  13. FOR XML PATH('')
  14. ) AS Concat

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.