Coba ini:
SELECT Name,
CAST(count AS VARCHAR(10)) + ',' + CAST(ProjectID AS VARCHAR(10))
AS Label FROM table1
Hasil
NAME LABEL ---------------------------- Security Services 32,1 Technical Services 32,7 Technical Services 31,2
Lihat SQLFiddle ini
Jika Anda ingin mengelompokkan berdasarkan Name
(Sesuatu seperti Group_Concate
di MySQL) tidak ada metode untuk itu di SQL Server. Itu hanya logika di baliknya.
Jadi, coba ini:
SELECT * FROM (
SELECT DISTINCT Name
FROM table1
) table2
CROSS APPLY
(SELECT CASE ROW_NUMBER()
OVER(ORDER BY ProjectId)
WHEN 1 THEN '' ELSE ': ' END +
(CAST(table3.count AS VARCHAR(10)) + ','
+ CAST(table3.ProjectID AS VARCHAR(10)) )
FROM table1 table3
WHERE table3.Name = table2.Name
ORDER BY ProjectID
FOR XML PATH ('')
) table3(Label)
Jadi hasilnya adalah
NAME LABEL -------------------------------- Security Services 32,1 Technical Services 31,2: 32,7