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

Bidang XML - Kueri

Inilah jawaban dengan operator xquery-->

declare @xmldata xml
    set @xmldata = 
    '<DynamicProfile xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WinTest">
  <AllData xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MyFirstKey</d2p1:Key>
      <d2p1:Value>MyFirstValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>
    <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MySecondKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>
    <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MySecondKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MyFirstKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MyFirstKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MySecondKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MySecondKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  <d2p1:KeyValueOfstringstring>
      <d2p1:Key>MyFirstKey</d2p1:Key>
      <d2p1:Value>MySecondValue</d2p1:Value>
    </d2p1:KeyValueOfstringstring>  </AllData>
</DynamicProfile>'

;WITH XMLNAMESPACES 
(
    DEFAULT 'http://schemas.datacontract.org/2004/07/WinTest',
    'http://schemas.microsoft.com/2003/10/Serialization/Arrays' as d2p1
)
SELECT  x.c.value('(d2p1:Key)[1]', 'varchar(100)') as key3, x.c.value('(d2p1:Value)[1]', 'varchar(100)') as value
FROM @xmldata.nodes('/DynamicProfile/AllData/d2p1:KeyValueOfstringstring') x(c) where x.c.value('(d2p1:Key)[1]', 'varchar(100)') = 'MySecondKey'


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Pernyataan Hapus SQL Server:Cara Menghapus Satu atau Mengalikan Baris dari Tabel

  2. Tablix:Ulangi baris tajuk pada setiap halaman tidak berfungsi - Pembuat Laporan 3.0

  3. T-SQL Query tabel matriks untuk posisi gratis

  4. Mengapa tidak ada opsi katalogisasi bilangan bulat yang dibatasi di SQL Server?

  5. Bagaimana saya bisa menunjukkan semua waktu antara 2 parameter waktu yang berbeda?