Ich versuche, XML von SQL Server zu erstellen, und ich bin mit verschachtelten Elementen fest. Ich versuche verschiedene FOR XML-Parameter, kann aber immer noch nicht die korrekten Ergebnisse erhalten.verschachteltes Element für XML in SQL Server
SELECT
Product.ID, Product.ProductName,
(SELECT
Images.ProductImage AS image
FROM Images
WHERE Images.ProductID = Product.ID
FOR XML PATH ('image_list'), ELEMENTS, TYPE
)
FROM (SELECT DISTINCT ID, ProductName FROM Product) Product
FOR XML PATH ('products'), ELEMENTS, root ('Root')
und ich will bekommen diese XML wie folgt aus::
Abfrage sieht wie folgt aus
<Root>
<products>
<ID>1</ID>
<ProductName>product 1</ProductName>
<image_list>
<image>picture1.jpg</image>
<image>picture2.jpg</image>
<image>picture3.jpg</image>
</image_list>
</products>
<products>
<ID>2</ID>
<ProductName>product 2</ProductName>
<image_list>
<image>picture1.jpg</image>
<image>picture2.jpg</image>
</image_list>
</products>
</Root>
Der erste Teil ist in Ordnung, ist die image_list ein Problem. Irgendein Rat?
Für Genuss der jeder ein Beispiel einer Ausgabe hinzufügen – Hogan