Query xml in SQL Server - escaping square brackets -
i trying query xml in sql server getting errors due data contains [
, ]
.
my xml format (third party cannot change format , rid of square brackets):
<myrootelement> <mychildelement name="[name1]"><mychildelement> <mychildelement name="[name2]"><mychildelement> <mychildelement name="[name3]"><mychildelement> </myrootelement>
i want records xml contains mychildelement
name.
i have tried:
select * mytable myxmlcolumn.exist(n'/myrootelement/myrootelement[@name=[name2]]') = 1
sql error message:
xquery invalid source character: [
if escape square brackets of [name]
(=[name1]
), complains &
so how can make query work?
is there better way?
literal string should goes in double quotes, no escaping needed case :
select * mytable myxmlcolumn.exist(n'/myrootelement/mychildelement[@name="[name2]"]') = 1
Comments
Post a Comment