I have this query:
select XMLMetadata from taObjectMetadata where ObjectMetadataTypeId = 1
which returns 3000+ rows, each row containing XML:
<objectMetaData>
<fileLocation fileName="CM63951.mxf06092018233409;21.png" />
</objectMetaData>
I need to pull that fileName out. I can do this for any given row easily enough with XQuery:
declare @x XML = ('<objectMetaData>
<fileLocation fileName="CM63951.mxf06092018233409;21.png" />
</objectMetaData>')
select x.value(N'@fileName', N'nvarchar(100)') as Filename
from @x.nodes(N'/objectMetaData/fileLocation') t(x)
Which gives me exactly the bit I need. However, I need this for every set of this XML in the table. Attempting to put the query in the declaration XML fails because it of course returns multiple results.
Do I need to use a WHILE loop here. or is there a better/more elegant way to do it?