---
title: "How to concatenate text from multiple rows into a single text string in SQL Server"  
description: "How to concatenate text from multiple rows into a single text string in SQL Server"  
author: "Sandra Emily"  
published: 2024-07-15  
updated: 2024-07-15  
canonical: https://www.mindstick.com/forum/160908/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to concatenate text from multiple rows into a single text string in SQL Server

How to [concatenate](https://www.mindstick.com/interview/1431/how-do-you-concatenate-strings-in-mysql) [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) from [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) rows into a single text [string in SQL](https://www.mindstick.com/interview/33826/how-to-find-the-length-of-a-string-in-sql-server) Server

## Replies

### Reply by Ashutosh Patel

You can contact multiple row values into a single text [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) value by using the SQL built-in function `STRING_AGG()`.

> Note- STRING_AGG() function supported in SQL Server version 2017 and later

## Syntax-

```plaintext
SELECT STRING_AGG(column_name, ', ') as ConcatedText FROM table_name
```

The `STRING_AGG()` function requires 2 argument(s), the first one is the **column name** and the second one is a **separater** between values as you see in the above syntax.

## Example-

suppose we have a `Employees` table.

```plaintext
CREATE TABLE Employees
(
	EmpId INT PRIMARY KEY NOT NULL,
	EmpName NVARCHAR(50),
	Gender NVARCHAR(20),
	Salary DECIMAL(10, 2)
)
```

Let's insert some values into above table,

```plaintext
INSERT INTO Employees
VALUES('Priya Shukla', 'Female', 70788),
('Ashutosh Verma', 'Male', 50066),
('Rani Sharma', 'Female', 57722),
('Amit Tiwari', 'Male', 81391),
('Ashu Patel', 'Male', 57659),
('Samiksha Mishra', 'Female', 15000),
('Akanksha Singh', 'Female', 15000);
```

As you can see in the below picture,

![How to concatenate text from multiple rows into a single text string in SQL Server](https://www.mindstick.com/mindstickforums/950ea6c7-3439-48d8-b7d3-6e9825814a6c/images/b0364ded-9b80-4cf4-b6af-0688049ead20.png)

## Example-

Now, use STRING_AGG() to concat multiple row values into a single string,

```plaintext
SELECT STRING_AGG(EmpName, ', ') as ConcatedText FROM Employees

-- output: Priya Shukla, Ashutosh Verma, Rani Sharma, Amit Tiwari, Ashu Patel, Samiksha Mishra, Akanksha Singh
```

**Also, Read:** [How to use searching and filtering data in an SQL server?](https://www.mindstick.com/forum/160900/how-to-use-searching-and-filtering-data-in-an-sql-server)


---

Original Source: https://www.mindstick.com/forum/160908/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
