SQL Server Concat String

Contoh query di SQL server untuk concat string di tabel one-to-many

[code language=”sql”]

select b.program_name, b.status,
STUFF((
SELECT ‘ ‘ + department
FROM order_assigned_departement
WHERE (order_assigned_departement.order_id = b.id)
FOR XML PATH (”))
, 1, 1, ”) AS department, b.submitted_date, group_id
from [order] b
where year(submitted_date) = 2017 and month(submitted_date) = 10 and b.cancellation_status is null
order by b.program_name

[/code]

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>