How to use WHERE on attribute in XML column in Sql Server 2008

KG

New Member
This is probably simple and I just don't get the braces right, but since I have virtually no experience in querying SQL SERVER XML data, it's driving me insane.I have a simple table with an XML typed column NoSqlField. This contains either NULL or\[code\]<root version="1.0"> <entry key="mykey">1</entry></root>\[/code\]I want all rows in the table that have a <entry key="mykey">1</entry> value in their NoSqlField column.A (rather stupid as it uses .ToString()) LINQ query using\[code\]where h.NoSqlField.ToString().IndexOf("<entry key=\"mykey\">1</entry>") > -1\[/code\]returns a result, so it's definitely there.How can I run the same query in T-SQL? I have tried\[code\]SELECT * FROM mytable WHERE NoSqlField.value('(//entry[@key=mykey])[1]','varchar(1)') = '1'\[/code\]in various variations (with and without slashes, full path,...) but never got a single returned row.
 
Back
Top