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 :: reorder primary key sql 
Sql :: hashpass 
Sql :: HOW to select specific table data from an mysql databse server: 
Sql :: search all tables in a database for a value 
Sql :: how to update date in oracle 
Sql :: create sql table from script inline primary key constraint 
Sql :: python sqlalcahmey compare datetime 
Sql :: mysql wait_timeout 
Sql :: como leer datos de mysql esp32 
Sql :: sqlite explain plan 
Sql :: eneratingSchemaError: Some errors occurred while generating GraphQL schema: Type Query must define one or more fields. 
Sql :: mysql create database if not exists 
Sql :: second highest salary in mysql 
Sql :: MySql shutdown unexpectedly InnoDB: Mutexes and rw_locks use Windows interlocked functions InnoDB: Uses event mutexes 
Sql :: Provera dupliranih konatakata 
Sql :: mysql select where field like in list 
Sql :: xampp increame mysql speed 
Sql :: BigQuery: join 2 tables but only choosing rows based on date column 
Sql :: ring get a list of tables inside the database using the odbc_tables() 
Sql :: To revoke create table from users 
Sql :: md5 encryption for existing records 
Sql :: plsql function that return a table 
Sql :: create table as select sql server error 
Sql :: watch mysql command line 
Sql :: drop column from table if exist on live server mysql 
Sql :: list of schema with sizes (relative and absolute) in a PostgreSQL database 
Sql :: extract sql from query object sqlalchemy 
Sql :: How To Execute SQL Select Statements 
Sql :: mysql clone table with data and add attribute 
Sql :: sql to linq converter online free 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =