Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Şunlar için geçerlidir:SQL Server
Azure SQL Veritabanı
Azure SQL Yönetilen Örneği
Microsoft Fabric'te SQL veritabanı
Bu örnekte HIDE yönergesinin kullanımı gösterilmektedir. Bu yönerge, sorgunun sorgu tarafından döndürülen evrensel tablodaki satırları sıralamak için bir öznitelik döndürmesini istediğinizde, ancak sonuçta elde edilen son XML belgesinde bu özniteliğin olmasını istemediğinizde kullanışlıdır.
Bu sorgu şu XML'i oluşturur:
<ProductModel ProdModelID="19" Name="Mountain-100">
<Summary>
<SummaryDescription>
<Summary> element from XML stored in CatalogDescription column
</SummaryDescription>
</Summary>
</ProductModel>
Bu sorgu istediğiniz XML'i oluşturur. Sorgu, sütun adlarında Etiket değerleri olarak 1 ve 2 içeren iki sütun grubunu tanımlar.
Bu sorgu, özet açıklamasını almak için xml türündeki CatalogDescription sütununu sorgulamak için xml veri türünün query() Yöntemini (xml Veri Türü) kullanır. Sorgu ayrıca, CatalogDescription sütunundan ProductModelID değerini almak için xml veri türünün value() Yöntemini (xml Veri Türü) kullanır. Sonuçta elde edilen XML'de bu değer gerekli değildir, ancak sonuçta elde edilen satır kümesini sıralamak için gereklidir. Bu nedenle, sütun adı, [Summary!2!ProductModelID!HIDE]HIDE yönergesini içerir. Bu sütun SELECT deyimine dahil değilse satır kümesini [ProductModel!1!ProdModelID] türüne göre [Summary!2!SummaryDescription] sıralamanız gerekir ve ORDER BY içinde xml türü sütununu kullanamazsınız. Bu nedenle, ek [Summary!2!ProductModelID!HIDE] sütun eklenir ve ORDER BY ifadesinde belirtilir.
USE AdventureWorks2022;
GO
SELECT 1 as Tag,
0 as Parent,
ProductModelID as [ProductModel!1!ProdModelID],
Name as [ProductModel!1!Name],
NULL as [Summary!2!ProductModelID!hide],
NULL as [Summary!2!SummaryDescription]
FROM Production.ProductModel
WHERE CatalogDescription is not null
UNION ALL
SELECT 2 as Tag,
1 as Parent,
ProductModelID,
Name,
CatalogDescription.value('
declare namespace PD="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
(/PD:ProductDescription/@ProductModelID)[1]', 'int'),
CatalogDescription.query('
declare namespace pd="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
/pd:ProductDescription/pd:Summary')
FROM Production.ProductModel
WHERE CatalogDescription is not null
ORDER BY [ProductModel!1!ProdModelID],[Summary!2!ProductModelID!hide]
FOR XML EXPLICIT;
GO
Sonuç şu şekildedir:
<ProductModel ProdModelID="19" Name="Mountain-100">
<Summary>
<SummaryDescription>
<pd:Summary xmlns:pd="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription" xmlns="">
<p1:p xmlns:p1="http://www.w3.org/1999/xhtml">Our top-of-the-line competition mountain bike. Performance-enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain. </p1:p>
</pd:Summary>
</SummaryDescription>
</Summary>
</ProductModel>