SQL: find if XML node exists

Assuming I have table data as below: Sample table

I want to select everything Value(XML Data) that the node contains Name="Hello World". How can i achieve this?

SQL Fiddle

set @f = @XML.exist('/ArrayOfFilterColumn/SelectColumn[(@Name) eq "Hello World"]');
select @f;

I am not sure how to add it to my condition, so I put it in a violin.

+4
source share
1 answer

Skip the use of the XML variable and place it in the where clause when querying the table.

select F.Value
from XML_FILES as F
where F.Value.exist('/ArrayOfArrayOfSelectColumn/SelectColumn[@Name eq "Hello World"]') = 1

Your column is apparently textwhy you need to change this because it has been textdeprecated and has been around for quite some time.

ntext, text and image (Transact-SQL)

, Microsoft SQL Server. , . nvarchar (max), varchar (max) varbinary (max).

, , XML.

, XML .

select F.Value
from XML_FILES as F
where cast(F.Value as xml).exist('/ArrayOfArrayOfSelectColumn/SelectColumn[@Name eq "Hello World"]') = 1
+6

All Articles