Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

XQUERY - Bagaimana cara menggunakan sql:variabel dalam fungsi 'value()'?

declare @T table(XMLCol xml)
insert into @T values
('<Root xmlns="http://tempuri.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Elem1 type="T1">
    <DisplayName type="string" display="Display name">No this</DisplayName>
    <Name type="string" display="First name">John</Name>
    <TimeZone display="Time zone">
      <children>
        <DisplayName type="string" display="Display name">GMT Standard Time</DisplayName>
        <HiddenName type="string" display="Hidden name">GMT</HiddenName>
      </children>
    </TimeZone>
  </Elem1>
</Root>') 

declare @Node1 varchar(50)
set @Node1 = 'TimeZone'

declare @Node2 varchar(50)
set @Node2 = 'DisplayName'

select N2.Value.value('.', 'varchar(100)') as Value 
from @T as T
  cross apply (select T.XMLCol.query('//*[local-name()=sql:variable("@Node1")]')) as N1(Value) 
  cross apply (select N1.Value.query('//*[local-name()=sql:variable("@Node2")]')) as N2(Value)


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Rata-Rata Bergerak / Rata-Rata Bergulir

  2. Ekspor tabel dari database ke file csv

  3. Cara Setup Database Mail di SQL Server (SSMS)

  4. Bagaimana cara mengatur properti SSRS ConsumeContainerWhitespace di Visual Studio 2008?

  5. Mengapa ini Pemindaian Indeks dan bukan Pencarian Indeks?