-2

I am trying to retrieve a list of comma separated product categories for a product.

Here is an idea of what I am trying to do:

SELECT *, (
  SELECT CategoryName 
  FROM ProductCategories pc 
  WHERE p.ProductId=pc.ProductId) as ProductCategories
FROM Products p

I need the product categories to be in a comma separated list. Is there a way to do it using COALESCE?

James Z
  • 12,104
  • 10
  • 27
  • 43
Matthew Peterson
  • 315
  • 1
  • 4
  • 17
  • No, not using `coalesce()`. But, if you google something like "SQL Server string aggregation", you'll find that this question has been asked before. – Gordon Linoff Jun 17 '15 at 14:17

1 Answers1

1

No, you can't use COALESCE to do that. COALESCE just returns the first non null argument that you pass it.

You want How to create a SQL Server function to "join" multiple rows from a subquery into a single delimited field?

Community
  • 1
  • 1
Bill Gregg
  • 6,909
  • 1
  • 20
  • 38