I am doing some XML querying in SQL and in order to get the attributes of multiple sibling nodes I need to do the following query:
select
C.value('@attribute[1]', 'varchar(30)')
from
tblData
cross apply
XmlFieldL.nodes('/Data/Children') as T(C)
By default the [1]
only gives the first item, so the cross apply gets around that and will give me a list of the @attribute
for each child node. Cool, works great.
My question is what is the syntax around the T(C)
? It looks like a function of some kind at first glance, or some kind of grouping. I reference the C, but why is the T portion necessary? What does the syntax mean?
For reference, this was the original problem/solution and better describes it. I'm just trying to understand exactly what I'm doing here.