Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am concatenating rows, and I want a row in different lines instead using a comma to separate them:
Persons
Sam
Rob
Bob
Tom
Tim 
/* something like that in the same row*/

I am using,
SELECT Person + CHAR(10) AS [text()]

but what only does is, works as a space between each new row.

Any hint?
Posted
Updated 23-Sep-10 2:28am
v2
Comments
Jyoti Ghunghru 5-Mar-20 7:22am    
On Windows, a newline is CHAR(13)+CHAR(10)
In the "INSERT" statement it will work but in the "SELECT" statement it will generate a White space, not a line break.

1 solution

If you want data in different lines then simple select query will work (assuming the data is in separate row):
<br />
SELECT Person from table_name<br />


If you want to concatenate the rows to single column, then check the following article:

http://databases.aspfaq.com/general/how-do-i-concatenate-strings-from-a-column-into-a-single-row.html[^]

http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/[^]

For new line, use
char(13) instead of char(10)

more info:
http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/[^]
 
Share this answer
 
Comments
jalmonte 23-Sep-10 7:31am    
Its doesnot work. If I used CHAR(13) it throw symbols like: �
Corporal Agarn 23-Sep-10 13:17pm    
Try SELECT Person + CHAR(13) + CHAR(10) AS mycolumn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900