Select specific rows with SQL Server XML column type

I am trying to select data from a table defined as follows:

Column     |    Data Type
-------------------------
Id         |    Int
DataType   |    Int
LoggedData |    XML

but I only want to select these rows with a specific DataType value and contain the row (or evaluate part of XPath) in the LoggedData column.

A quick Google search didn’t bring anything useful, and I’m in a hurry to get an answer ... I will continue to search, but if anyone can help me at this time, I really appreciate it.

EDIT _ Clarification

So what I need is something like this, but in the correct format ...

select Id, LoggedData from myTable where DataType = 29 and LoggedData.query('RootNode/ns1:ChildNode[@value="searchterm"]');

It may still be unclear ...

+2
source share
2 answers

(, SQL), , , - :

Select Id, LoggedData From myTable Where DataType = 29 And 
LoggedData.exist('RootNode/ns1:ChildNode[@value=sql:variable("@searchterm")]')=1

@searchterm - SQL.

+1

?

SELECT
  Id, 
  LoggedData 
FROM
  myTable 
WHERE
  DataType = 29 
  AND LoggedData.exist('RootNode/ns1:ChildNode[@value="searchterm"]') = 1
0

Source: https://habr.com/ru/post/1699585/


All Articles