About 1,680,000 results
Open links in new tab
  1. How to concatenate text from multiple rows into a single text …

    Oct 27, 2015 · In SQL Server 2005 and later, use the query below to concatenate the rows. DECLARE @t table ( Id int, Name varchar(10) ) INSERT INTO @t SELECT 1,'a' UNION ALL SELECT 1,'b' UNION ALL SELECT 2,'c' UNION ALL SELECT 2,'d' SELECT ID, stuff( ( SELECT ','+ [Name] FROM @t WHERE Id = t.Id FOR XML PATH('') ),1,1,'') FROM (SELECT DISTINCT ID …

  2. How to Concatenate Text From Multiple Rows in SQL Server

    Feb 2, 2024 · In this article, we will discuss how to concatenate text from multiple rows into a single text string in SQL Server using various methods which are COALESCE Function, XML PATH Function, and STUFF Function with XML PATH and Group By Clause.

  3. Concatenate 2 rows into one in SQL - Stack Overflow

    Dec 3, 2021 · Finally, concatenate these 2 properties into one. The best I could do is: (SELECT CONCAT(e.title, ' / ') FROM employees AS e WHERE e.id = (SELECT r.resposible_employee_id FROM requests AS r WHERE r.id = 1)) UNION (SELECT t.title FROM teams AS t WHERE t.id = (SELECT r.responsible_team_id FROM requests AS r WHERE r.id = 1))

  4. How to concatenate rows into one cell and add break line after …

    Mar 13, 2019 · You should do that in the presentation layer not in SQL. As you are using SQL server 2017 you can use STRING_AGG function. p.PersonID, . STRING_AGG( Language + '(' + . CASE cvnl.Proficiency . WHEN 1 THEN 'Good' WHEN 2 …

  5. Rolling up multiple rows into a single row and column for SQL

    Dec 19, 2024 · Learn how to roll-up multiple rows into one row and one column with concatenation in SQL Server with FOR XML, STUFF and STRING_AGG.

  6. How to combine rows into one string in SQL [SOLVED]

    Nov 16, 2022 · To concatenate multiple rows into a single string using COALESCE method first we need to declare a variable of varchar type to store combined strings inside the coalesce, use a comma separator to differentiate each row string value in concated string then assign the COALESCE to the variable.

  7. SQL Concatenate Examples - MSSQLTips.com - SQL Server Tips

    Oct 5, 2021 · In any version of SQL Server, you can use the plus sign as a concatenation operator with the following syntax: SELECT 'Hello'+' World'+'!' It doesn’t really matter if you’re using string literals or variables or columns values to concatenate strings.

  8. SQL Server: Concatenate Multiple Rows Into Single String

    Jan 6, 2017 · There are multiple ways to concatenate rows into string. Now we will see a couple of the easiest techniques here. 1. Concatenate Multiple Rows Using FOR XML PATH. The simplest and straight forward way to concatenate rows into a string value is to use FOR XML PATH in a select query.

  9. How to concatenate text from multiple rows into a single text

    Oct 15, 2023 · If you want to display all the names in one string and you are using SQL Server after 2017, you can use the STRING_AGG function to concatenate multiple rows:

  10. Join two tables and concatenate multiple rows of a single field

    May 6, 2014 · I would like to join two tables, #Table1 and #Tabl2, on a key column, ID, and get Value field from the 2nd table... but in a single row (as shown in desired output). How (if possible) can I achieve the Desired Output?

Refresh