1

Topic: xml - attribute of root level node

I want Date from root level node.
But I can not.
It is possible?

declare @xml xml = ' <ValCurs Date = "3/6/2018" name = "Foreign Currency Market">
<Valute ID = "R01010">
<NumCode> 036 </NumCode>
<CharCode> AUD </CharCode>
<Nominal> 1 </Nominal>
<Name> the Australian dollar </Name>
<Value> 44,2125 </Value>
</Valute>
<Valute ID = "R01020A">
<NumCode> 944 </NumCode>
<CharCode> AZN </CharCode>
<Nominal> 1 </Nominal>
<Name> Azerbaijan  </Name>
<Value> 33,5389 </Value>
</Valute>
</ValCurs> ';
select row = t.n.query ('. ')
, id = t.n.value (' (@ID) [1] ', ' nvarchar (64) ')
, NumCode = t.n.value (' (./NumCode) [1] ', ' nvarchar (64) ')
, CharCode = t.n.value (' (./CharCode) [1] ', ' nvarchar (64) ')
, Nominal = t.n.value (' (./Nominal) [1] ', ' int ')
, Name = t.n.value (' (./Name) [1] ', ' nvarchar (256) ')
, Value = try_cast (replace (t.n.value (' (./Value) [1] ', ' nvarchar (64) '), ', ', '. ') as money)
, Data = @xml.value (' (/ValCurs / Data) [1] ', ' nvarchar (64) ')-??????????????
from @xml.nodes ('/ValCurs/Valute ') as t (n)
;

2

Re: xml - attribute of root level node

Oh, sorry, transfer in MS SQL

3

Re: xml - attribute of root level node

Is better delete.