Search
 
SCRIPT & CODE EXAMPLE
 

SQL

How to concatenate text from multiple rows into a single text string in SQL Server

SELECT STRING_AGG(Name, ', ') AS Departments
FROM HumanResources.Department;
Comment

concatenate text from multiple rows into a single text stringin SQL Server

SELECT Main.SubjectID,
       LEFT(Main.Students,Len(Main.Students)-1) As "Students"
FROM
    (
        SELECT DISTINCT ST2.SubjectID, 
            (
                SELECT ST1.StudentName + ',' AS [text()]
                FROM dbo.Students ST1
                WHERE ST1.SubjectID = ST2.SubjectID
                ORDER BY ST1.SubjectID
                FOR XML PATH (''), TYPE
            ).value('text()[1]','nvarchar(max)') [Students]
        FROM dbo.Students ST2
    ) [Main]
Comment

PREVIOUS NEXT
Code Example
Sql :: ring SQLite sqlite_init 
Sql :: android sqlite query con join 
Sql :: laravel How to find the password of mysql on desktop docker in laravel 
Sql :: sqlserver now 
Sql :: oarcale list objects 
Sql :: what is the difference between an embedded database and a normal 
Sql :: convert mongodb to sql 
Sql :: Perfect solution if some records deleted for LAST_ID 
Sql :: mysql grant user wildcard database 
Sql :: select concat alter table mysql 
Sql :: sql alchemy escape ; in insert statement 
Sql :: is there any limit of using joins in single mysql query ? 
Sql :: SQL Copy Records Matching a Condition 
Sql :: inner joint 
Sql :: sqlalchemy sequence postgresql 
Sql :: float in sql 
Sql :: in operator in sql 
Sql :: create database ms sql server 
Sql :: in condition in sql 
Sql :: sql select data from one database and insert into a different database 
Sql :: How to Remove milliseconds from Date time 
Sql :: stored procedure to change name of column for all dependent tables and views 
Csharp :: c# get number of files in directory 
Csharp :: c# random number between 1 and 100 
Csharp :: how to detect a mouse click in unity 
Csharp :: textmeshpro text 
Csharp :: how to call something once in update 
Csharp :: wpf bind to self 
Csharp :: c# get full URL of page 
Csharp :: c# datagridview clear all rows 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =