Я пытаюсь разобрать JSON
с помощью функции OPENJSON
с помощью CROSS APLY
, но у меня есть некоторые проблемы.
Мой Json выглядит так:
[
{
"Communications":[
{
"ID_Communication":null,
"CommunicationType":"HOME",
"CommunicationValue":"0602060206",
"Priority":0,
"Disabled":false
},
{
"ID_Communication":null,
"CommunicationType":"MOBILE",
"CommunicationValue":"0602060306",
"Priority":0,
"Disabled":false
},
{
"ID_Communication":null,
"CommunicationType":"EMAIL",
"CommunicationValue":"MONEMAIL@EMAIL.FR",
"Priority":0,
"Disabled":false
}
],
"InternalId":23126,
"ExternalId":"",
"LastUpdateDate":"2020-01-05T12:04:53",
"Type1":{
"Id":1
},
"Type2":{
"Id":2
},
"Type3":null,
"Title":{
"Id":1
},
"LastName":"TOTO",
"FirstName":"TITI",
"OrganizationName":"",
"Sex":"M",
"BirthDate":"1959-10-07T00:00:00",
"Adresses":[
{
"ID_Address":null,
"Address1":"1 RUE DE FRANCE",
"Address2":"",
"Address3":"",
"Address4":null,
"ZipCode":"94500",
"CityName":"MA VILLE",
"Country":{
"Id":"FR"
},
"Type":null,
"State":null,
"Priority":0,
"ScopeId":0
}
],
"Language":{
"Id":"FR"
},
"Comment":"",
"PassportNumber":"",
"IdentityCardNumber":"",
"Nationality":null,
"SocialGroup":{
"Id":1
},
"OptIns":[
{
"OptInType":"OPT_CLUB",
"OptInLabel":"Optin club",
"OptInValue":0
},
{
"OptInType":"OPT_PART",
"OptInLabel":"Optin partenaires",
"OptInValue":0
}
],
"WebLogin":"MONEMAIL@EMAIL.FR"
}
]
Я попытался выполнить запрос, подобный следующему: Этот запрос пытается получить различную информацию об этом JSON.
declare @JSON_CONTACT nvarchar(MAX)
SELECT @JSON_CONTACT = '[
{
"Communications":[
{
"ID_Communication":null,
"CommunicationType":"HOME",
"CommunicationValue":"0602060206",
"Priority":0,
"Disabled":false
},
{
"ID_Communication":null,
"CommunicationType":"MOBILE",
"CommunicationValue":"0602060306",
"Priority":0,
"Disabled":false
},
{
"ID_Communication":null,
"CommunicationType":"EMAIL",
"CommunicationValue":"MONEMAIL@EMAIL.FR",
"Priority":0,
"Disabled":false
}
],
"InternalId":23126,
"ExternalId":"",
"LastUpdateDate":"2020-01-05T12:04:53",
"Type1":{
"Id":1
},
"Type2":{
"Id":2
},
"Type3":null,
"Title":{
"Id":1
},
"LastName":"TOTO",
"FirstName":"TITI",
"OrganizationName":"",
"Sex":"M",
"BirthDate":"1959-10-07T00:00:00",
"Adresses":[
{
"ID_Address":null,
"Address1":"1 RUE DE FRANCE",
"Address2":"",
"Address3":"",
"Address4":null,
"ZipCode":"94500",
"CityName":"MA VILLE",
"Country":{
"Id":"FR"
},
"Type":null,
"State":null,
"Priority":0,
"ScopeId":0
}
],
"Language":{
"Id":"FR"
},
"Comment":"",
"PassportNumber":"",
"IdentityCardNumber":"",
"Nationality":null,
"SocialGroup":{
"Id":1
},
"OptIns":[
{
"OptInType":"OPT_CLUB",
"OptInLabel":"Optin club",
"OptInValue":0
},
{
"OptInType":"OPT_PART",
"OptInLabel":"Optin partenaires",
"OptInValue":0
}
],
"WebLogin":"MONEMAIL@EMAIL.FR"
}
]'
DROP TABLE TEMP_JSON_RCT_TEST_PARSE
SELECT *
INTO TEMP_JSON_RCT_TEST_PARSE
FROM OPENJSON (@JSON_CONTACT)
WITH (
FIRSTNAME nvarchar(50) '$.FirstName',
LASTNAME nvarchar(50) '$.LastName',
Sex nvarchar(2) '$.Sex',
BirthDate date '$.BirthDate',
Communications nvarchar(max) AS JSON
) AS Communications
CROSS APPLY OPENJSON(Communications)
WITH (
CommunicationType nvarchar(50),
CommunicationValue nvarchar(50),
Adresses nvarchar(max) AS JSON
) AS Adresses
CROSS APPLY OPENJSON(Adresses)
WITH (
Address1 nvarchar(100)
)
Я хотел бы получить возвращаемое значение:
FIRSTNAME, LASTNAME, SEX, BIRTHDATE, EMAIL, MOBILE, HOME, LASTUPDATEDATE, ADDRESS1, ADRESSE2, ADDRESSE3, ADDRESS4, ZIPCODE, CITYNAME, OPT_CLUB, OPT_PART
VALUES:
MY FIRSTNAME, MYLASTNAME, M, 09/05/1989, MONEMAIL@EMAIL.FR, 0602060306,0602060206, 2020-01-05T12:04:53, 1 RUE DE FRANCE, , , , 94500, MA VILLE, 0, 0
Когда я выполняю свой запрос, который возвращает ноль, я не понимаю, почему.
Можете ли вы помочь с этим?