Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Extract value from a sql column that contains XML

$
0
0

'm trying to get the value from a column in a SQL Server table that contains XML but the type of the column is not XML it is TEXT.

I tried this:

SELECT
    [Id],
    [Request]
FROM
    [Tracker]
WHERE
    [Request].value('/Credit[1]/Loan[1]/LoanApp[1]/Applicant[1]/Personal[1]/Individals[1]/Individual[1]/GivenName[1]/FirstName[1]', 'nvarchar(50)') = 'Tom'

but I get this error :

Cannot find either column "Request" or the user-defined function or aggregate "Request.value", or the name is ambiguous.

I tried to cast the column like this:

select
    CAST(CAST(Request AS NTEXT) AS XML).value('(/Credit[1]/Loan[1]/LoanApp[1]/Applicant[1]/Personal[1]/Individuals[1]/Individual[1]/GivenName[1]/FirstName[1]', 'nvarchar(50)')
from Tracker

but with this I get this error:

XML parsing: line 1, character 15, A string literal was expected


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>