Possible Duplicate:
Simulating group_concat MySQL function in MS SQL Server 2005?
I have a table tb1. I want concatenated result set.
Please help me by writing a query for this problem?
Possible Duplicate:
Simulating group_concat MySQL function in MS SQL Server 2005?
I have a table tb1. I want concatenated result set.
Please help me by writing a query for this problem?
Here, try this one,
SELECT a.dept_id,
NewTable.NameValues
FROM (
SELECT DISTINCT dept_ID
FROM tableA
) a
LEFT JOIN
(
SELECT dept_id,
STUFF((
SELECT ', ' + [Name]
FROM tableA
WHERE ( dept_id = Results.dept_id )
FOR XML PATH('')), 1, 1, '') AS NameValues
FROM tableA Results
GROUP BY dept_id
) NewTable
on a.dept_id = NewTable.dept_id
GO
HEre's another version
SELECT a.dept_id,
SUBSTRING(d.nameList,1, LEN(d.nameList) - 1) ConcatenateNames
FROM
(
SELECT DISTINCT dept_id
FROM tableA
) a
CROSS APPLY
(
SELECT name + ', '
FROM tableA AS B
WHERE A.dept_id = B.dept_id
FOR XML PATH('')
) D (nameList)
GO
Try this:
select col1 + ' ' + col2 from bla.bla.bla