clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591614 fiddles created (45711 in the last week).

DECLARE @J NVARCHAR(MAX) = N'{ "products": [ { "description": "Horse shoes", "productid": 1, "orders": [ { "customerid": 101 }, { "customerid": 102 }, { "customerid": 103 } ] }, { "description": "Horse food", "productid": 2, "orders": [ { "customerid": 104 }, { "customerid": 105 }, { "customerid": 106 } ] } ]}' SELECT ProductID ,Description ,CustomerID FROM OPENJSON(@j) WITH ( Products NVARCHAR(MAX) '$.products' AS JSON ) AS J CROSS APPLY OPENJSON(J.Products) WITH ( Description NVARCHAR(255) '$.description', ProductID INT '$.productid', Orders NVARCHAR(MAX) '$.orders' AS JSON ) AS Products CROSS APPLY OPENJSON(Products.Orders) WITH ( CustomerID INT '$.customerid' )
ProductID Description CustomerID
1 Horse shoes 101
1 Horse shoes 102
1 Horse shoes 103
2 Horse food 104
2 Horse food 105
2 Horse food 106
 hidden batch(es)