Ich versuche, zwei SQL-Tabellen mit innerer Verknüpfung beizutreten und sie dann als JSON von meiner Prozedur zurückzugeben.SQL Inner Join mit Für JSON-Hierarchie
Meine select-Anweisung ist:
SELECT
@CustomerAddressesJSON =
(SELECT
Address.AddressID, Address.CustomerID,
Address.AddressTypeID, Address.IsPrimary,
CountryID, StateID, CountyID, DistrictID,
StreetID, StreetNumber, PostalCode,
AdditionalInformation, AddressImageID,
CreatedOn, CreatedBy
FROM
[sCustomerManagement].[tCustomerAddresses] Address
INNER JOIN
[sCustomerManagement].[tAddresses] AddressDetails ON Address.AddressID = AddressDetails.AddressID
WHERE
CustomerID = @CustomerID
FOR JSON AUTO)
und das Ergebnis ist wie folgt aus:
"customerAddressesJSON": "[
{
"AddressID":1,
"CustomerID":1,
"AddressTypeID":"T",
"IsPrimary":true,
"AddressDetails":[
{
"CountryID":1,"StateID":1,"CountyID":1,"DistrictID":1,"StreetID":1,"StreetNumber":"125","PostalCode":"1000","AdditionalInformation":"Metro Sofia","CreatedOn":"2017-10-24T11:46:20.1933333","CreatedBy":24
}
]
},
{
"AddressID":2,
"CustomerID":1,
"AddressTypeID":"T",
"IsPrimary":true,
"AddressDetails":[
{
"CountryID":1,"StateID":1,"CountyID":1,"DistrictID":1,"StreetID":1,"StreetNumber":"125","PostalCode":"1000","AdditionalInformation":"Metro Sofia","CreatedOn":"2017-10-24T11:46:20.1933333","CreatedBy":24
}
]
}
Das Problem ist, dass ich zu verschachtelt die Informationen nicht in dem Array AddressDetails möge. Ist es möglich, dass die Information dort draußen ist, damit ich 2 flache Objekte ohne verschachtelte Informationen empfangen kann?
Dank
Glad zu helfen. Neugierig, OP, welche Lösung hat für Sie funktioniert? – Parfait