Your XPath expression may return multiple rows for each row in a SQL Server table. To get this information, you need to use CROSS APPLY and the .nodes() call:
WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume' AS ns) SELECT JobCandidateID, ResNames.value('(ns:Name.First)[1]', 'nvarchar(100)') FROM HumanResources.JobCandidate CROSS APPLY [Resume].nodes('/ns:Resume/ns:Name') AS XTbl(ResNames)
This should return all JobCandidateID values ββand all names defined in the Resume XML column for each row of the table.
If you can be sure that your XML column will have only one <name> , you can also shorten it to:
WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume' AS ns) SELECT JobCandidateID, [Resume].value('(/ns:Resume/ns:Name/ns:Name.First)[1]', 'nvarchar(100)') FROM HumanResources.JobCandidate
source share