0

FYI: I'm using SQL Server.

I have a table where I query for one column but it may contain multiple records:

SELECT CodeNumber
FROM Books
WHERE Type='Children'

CodeNumer
---------
A
B
C
D
E

I want to PIVOT the table and concatenate the column data into a computed column such that it looks like this:

ComputedColumn
--------------
A; B; C; D; E;

I'm open to using something else other than pivot in the query. I'd prefer not to write a stored procedure which will perform this action.

Thank you for any help.

user3621633
  • 1,681
  • 3
  • 32
  • 46
  • 1
    This doesn't appear to be a `PIVOT` because you aren't turning those values into columns, since you want to concatenate them into a single row the duplicate should offer a variety of ways to solve it. – Taryn May 09 '16 at 21:03
  • 1
    No problem. I don't know what the protocol is, as far as if this question should be deleted, but I found my answer from the duplicate: `SELECT STUFF( ( SELECT ' ' + CodeNumber + ';' FROM Books WHERE Type='Children' FOR XML PATH( '' ) ), 1, 1, '')`. Thank you so much for pointing out that question! I thought `PIVOT` was the answer but, you're right, I'm not turning values into columns. – user3621633 May 09 '16 at 21:20

0 Answers0