There is 2 ways I know :
------------------------------------------------------------------------------------------
DECLARE @List VARCHAR(MAX)
SELECT
@List = ISNULL(EmployeeID + ', ' , '') + @List
FROM
Employee
SELECT @List
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
SELECT
LEFT(CA.List, LEN(CA.List)-1)
FROM
(
SELECT
CONVERT(VARCHAR(100),EmployeeID) + ',' AS [text()]
FROM
Employee
FOR XML PATH('')
)CA(List)
-------------------------------------------------------------------------------------------
Sometimes way no 2 faster than no 1, but for some condition no 1 is faster.
No comments:
Post a Comment