Linked Questions
474 questions linked to/from How to concatenate text from multiple rows into a single text string in SQL Server
216
votes
13
answers
179k
views
How to create a SQL Server function to "join" multiple rows from a subquery into a single delimited field? [duplicate]
To illustrate, assume that I have two tables as follows:
VehicleID Name
1 Chuck
2 Larry
LocationID VehicleID City
1 1 New York
2 1 Seattle
3 ...
110
votes
10
answers
494k
views
Convert multiple rows into one with comma as separator [duplicate]
If I issue SELECT username FROM Users I get this result:
username
--------
Paul
John
Mary
but what I really need is one row with all the values separated by comma, like this:
Paul, John, Mary
How do I ...
113
votes
1
answer
472k
views
Multiple rows to one comma-separated value in Sql Server [duplicate]
I want to create a table valued function in SQL Server, which I want to return data in comma separated values.
For example table: tbl
ID | Value
---+-------
1 | 100
1 | 200
1 | 300
1 | 400
...
53
votes
6
answers
196k
views
SQL Query - Concatenating Results into One String [duplicate]
I have a sql function that includes this code:
DECLARE @CodeNameString varchar(100)
SELECT CodeName FROM AccountCodes ORDER BY Sort
I need to concatenate all results from the select query into ...
76
votes
5
answers
102k
views
Can I Comma Delimit Multiple Rows Into One Column? [duplicate]
I am attempting to merge something like this in my SQL Server database:
[TicketID], [Person]
T0001 Alice
T0001 Bob
T0002 Catherine
T0002 Doug
T0003 Elaine
Into ...
39
votes
1
answer
128k
views
comma delimited list as a single string, T-SQL [duplicate]
My T-SQL query generates following result set
ID Date
756 2011-08-29
756 2011-08-31
756 2011-09-01
756 2011-09-02
How can I convert like this
ID Date
756 2011-08-29, 2011-08-31,...
16
votes
3
answers
56k
views
SQL Server select results as string separated with ',' [duplicate]
I have a select query that returns one column and I want to convert that to string rows separated with ','
Select name
from tblUsers
Gives a result:
Row1; asieh
Row2:amir
Row3:safoora
I want to ...
5
votes
2
answers
21k
views
get a comma delimited string from rows [duplicate]
What will be the query in MS Sql Server to concatenate my rows in one string , delimited by comma (Like shown below)
4
votes
4
answers
41k
views
T-SQL Concatenate & group multiple rows into a single row [duplicate]
I'm looking for a way to group whilst also concatenating rows into a comma separated string.
Example:
Name Place
Steve Jones New York
Steve Jones Washington
Albert Smith Miami
...
9
votes
2
answers
29k
views
Sql select group by and string concat [duplicate]
i have a table like this
ID NAME Amount
1 cal 100
2 cal 200
3 cal 300
4 cal 400
1 ser 500
2 ser 600
5 ser 700
i want to write a select query so that i ...
6
votes
3
answers
14k
views
Concatenate a single column into a comma delimited list [duplicate]
I've seen multiple examples of people rolling up a single column into a comma delimited list, but I need a bit more.
Here is an example of the data and results I need.
DECLARE @SalesPerson table (...
6
votes
1
answer
33k
views
How to concatenate multiple rows into one field in sql server [duplicate]
Using simple query , I can do something like
SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
and get:
shopping
fishing
coding
but instead I just want 1 row, 1 col:
shopping, fishing, ...
8
votes
3
answers
5k
views
SQL Server, how can I transpose data of a column [duplicate]
Possible Duplicate:
Concatenate many rows into a single text string?
I have a query
SELECT city FROM cityTable
it returns
delhi
faridabad
haryana
mathura
kerla
I just want result in transpose ...
7
votes
1
answer
4k
views
Accomplishing MYSQL's Group_Concat in SQL Server [duplicate]
I'm porting an application I originally wrote to run on Apache using PHP and a MySQL database. One of the queries used the MySQL functions of Concat_WS and Group_Concat to first concatenate a few ...
5
votes
1
answer
5k
views
Select multiple SQL rows into one row [duplicate]
Possible Duplicate:
Concatenate many rows into a single text string?
Suppose I have table named tblContractMail. Sample table with data given below:
I need to write a SQL query that produces ...