I am trying to combine rows in table for my query. All information is the same for each field but "order comments". I want to combine the duplicate rows and have the order comments all in one row like as:
Table name : Orders
Order number | Name | Date | Order Comments |
---|---|---|---|
123 | John | 5.2 | Careful |
123 | John | 5.2 | Call Before |
456 | Dave | 6.3 | Asap |
456 | Dave | 6.3 | Call Before |
Order number | Name | Date | Order Comments |
---|---|---|---|
123 | John | 5.2 | Careful, Call Before |
456 | Dave | 6.3 | Asap, Call before |
Tried:
SELECT ORDER NUMBER, NAME, DATE, ORDER COMMENTS, string_agg(isnull(Order Comments, ' '),', ') AS ORDER COMMENTS
FROM Orders
GROUP BY ORDER NUMBER, NAME;
Result:
wrong number of arguements used with function in query expression "string_agg(convert(nvarchar(max), isnull(order comments,'n/a')),',"