SQL Server: How do I check if an element attribute of an xml node contains a specific string? -



SQL Server: How do I check if an element attribute of an xml node contains a specific string? -

i've xml document this.

<students> <student> <node type="http://www.something.com/xyz/10/abc/rollnumber" value="original=10000;modified=100003445" /> <node type="http://www.something.com/xyz/10/abc/serialnumber" value="original=10000;modified=172777" /> <node type="http://www.something.com/xyz/10/abc/stream" value="original=cs;modified=ec" /> </student> </students>

to value of stream, can write:

select @myxml.value('(/students/student/node[@type="http://www.something.com/xyz/10/abc/stream"]/@value)[1]', 'varchar(100)') changedvalue

my problem url part may change, hence want match based on criteria

@type = "%stream"

or

@type.contains("stream")

is possible?

the xpath engine in sql supports contains function, can say:

select @myxml.value('(/students/student/node[contains(@type,"stream")]/@value)[1]', 'varchar(100)') changedvalue

unfortunately however, obvious ends-with() xpath 2.0 function, , sql engine doesn't offer that, if wanted test string ending with stream you'd have (as per this post):

select @myxml.value ('(/students/student/node["stream" = substring(@type, string-length(@type)-5)]/@value)[1]', 'varchar(100)') changedvalue

sql-server xml xpath

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -