3

can any one tell me how Local.name(.) xquery function works. regarding sql construction problem i post a question in a forum and they give me answer. where Local.name(.) xquery function is used but syntax is not clear to me very well.

;with cte as
(
select x.i.value('local-name(.)','nvarchar(MAX)') as colname
,x.i.value('.','nvarchar(max)') as data
from @x.nodes('/Record/DELETED/*') as x(i))

what is the meaning of this line x.i.value('local-name(.)','nvarchar(MAX)') as colname why 'local-name(.)' what is local-name (.) what does it mean. again x.i.value('.','nvarchar(max)') as data please explain the two line in detail. i am not advance user. thanks a lot.

please guide me. thanks

gbn
  • 422,506
  • 82
  • 585
  • 676
Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

7

local-name(.) will give you the node name of the current node. If you used local-name(..) you would get the node name of the parent node.

x.i.value('.','nvarchar(max)') will give you the content of the the current node.

@x.nodes('/Record/DELETED/*') gives you all nodes in /Record/Deleted.

So your query will give you a name/value list of all nodes in /Record/Deleted.

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281