pyrospade
pyrospade

Reputation: 8078

Query each node's inner content

I know that I can do this -

declare @args xml = '<arg><value>hello</value></arg><arg><value>world</value></arg>';

select arg.value('value[1]', 'nvarchar(max)')
from @args.nodes('//arg') args(arg);

But I'd like to do something like this (without the superfluous <value> tags) -

declare @args xml = '<arg>hello</arg><arg>world</arg>';

select arg.value('?', 'nvarchar(max)')
from @args.nodes('//arg') args(arg);

What's the right XQuery expression?

Upvotes: 0

Views: 34

Answers (1)

JohnLBevan
JohnLBevan

Reputation: 24470

declare @args xml = '<arg>hello</arg><arg>world</arg>';

select arg.value('text()[1]', 'nvarchar(max)')
from @args.nodes('//arg') args(arg);

Upvotes: 1

Related Questions