I was referring to this : How to query values from xml nodes? and tried to find the best and quick way to search the node values, if exists, but somehow it looks completed explanation than that I was originally thinking.
There are around 10K records in the DB table. One of the column stores the XML in the table, the column value is just similar to this ( with lot many other nodes):
<GrobReportXmlFileXmlFile>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>Hello</OrganizationReportReferenceIdentifier>
<OrganizationNumber>Hi</OrganizationNumber>
</ReportHeader>
</GrobReport>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>Find</OrganizationReportReferenceIdentifier>
<OrganizationNumber>Me</OrganizationNumber>
</ReportHeader>
</GrobReport>
The script I have tried is:
select columnname.value('(GrobReportXmlFileXmlFile/GrobReport/ReportHeader/OrganizationReportReferenceIdentifier/)[Hello]',nvarchar(max)) from Table
Note: My columnname is:
columnname(nvarchar(max),null)
However, its showing error, nvarchar is not recognized by build-in function.
I have changed my query like this:
select T.[columnname].value('(GrobReportXmlFileXmlFile/GrobReport/ReportHeader/OrganizationReportReferenceIdentifier/)[Hello]','nvarchar(max)') from Table as T
However, in this case I'm getting error as:
Can not call method on nvarchar(max)
Any idea, if .value needs to be replaced by some other function as its type is nvarchar(max)? Is there any alternative for "value" function, that I can try?
I would like to find if any particular value (lets say "Hello") exist in any of the column/node or not?If it exists then it should return me the number of records(rows) in which the searched value present?
Thanks