When I use FOR XML PATH('') in the following query, the role values come back fine but for each result the FirstName value is <Unknown(-16)>
. Here is the query:
SELECT role, STUFF((SELECT ','+FirstName FROM Employees WHERE role = 'Engineer' FOR XML PATH('')),1,1,'') AS names FROM Employees GROUP BY role
I have tried to find this error code online but have had no luck, has anyone seen this error before in SQL Server and knows how to resolve it?
Update: Just to clarify, if I reduce my query to just this I can still reproduce the error:
SELECT ','+FirstName FROM Employees WHERE role = 'Engineer' FOR XML PATH('')
So this may be an environment issue. I am on SQL Server 2005 SP2. Also note that I am running the query via JDBC (not sure if this matters).