I have the following code but I am getting the error,
Msg 537, Level 16, State 3, Line 1
Invalid length parameter passed to the LEFT or SUBSTRING function.
Code:
SELECT
Main.HostName, LEFT(Main.Users, Len(Main.Users) - 1) AS [Users]
FROM
(SELECT DISTINCT
ST2.HostName,
(SELECT ST1.UserName + ', ' AS [text()]
FROM dbo.USERS ST1
WHERE ST1.HostName = ST2.HostName
ORDER BY ST1.HostName FOR XML PATH('')) [Users]
FROM
dbo.USERS ST2) [Main]
I am trying to left most user in each row.