Hello everybody.
I'm trying to display all the JSON fields, but I can't. Thanks to anyone who can help me.
1 - JSON structure
'{
"status": "SUCCESS",
"VentaPajaros": {
"codigoClient": 13216598,
"composicionParcelas": [
{
"id": "07"
},
{
"id": "08"
}
],
"pago": {
"fechaprimerpago": "09/12/2022",
"datosventa": {
"valor": 304.63,
"valorMinimo": 522.57
},
"cuota": {
"valor": 174.07,
"valorMinimo": 176.64
}
},
"composicionAcuerdo": {
"totalDeuda": 1490.62,
"iof": 0,
"notificacion": 0,
"gestionProtesta": 0
}
}
}'
2 - Query
SELECT
[status]
,codigoClient
,id
,fechaprimerpago
,valor as cuota_valor
FROM OPENJSON(@json)
with([status] varchar(50) '$.status'
,VentaPajaros nvarchar(max) as json )
outer apply openjson ( VentaPajaros )
with(codigoClient varchar(50) '$.codigoClient'
,composicionParcelas nvarchar(max) as json )
outer apply openjson ( composicionParcelas )
with(id int '$.id'
,pago nvarchar(max) as json )
outer apply openjson ( pago )
with(fechaprimerpago varchar(10) '$.fechaprimerpago'
,cuota nvarchar(max) as json )
outer apply openjson ( cuota )
with(valor varchar(10) '$.cuota.valor'
)
3 - Result
status codigoClient id fechaprimerpago cuota_valor
SUCESS 13216598 7 NULL NULL
SUCESS 13216598 8 NULL NULL
Thanks to anyone who can help me.