im new to JSON - Code and i have a cell in the SQL Server at my work from a database that is in JSON-format.
Here is the JSON String in the database:
{
"fields":{
"field":[
{
"result":0,
"isrequired":"true",
"name":"empfohlene Garantiebewertung",
"type":"eEnumeration",
"facets":[
{
"facet":[
{
"id":0,
"type":"Enumeration",
"value":"keine Garantie;Garantie ;Kulanz"
},
{
"id":1,
"type":"choicetype",
"value":"singlechoice"
},
{
"id":2,
"type":"ErrorRange",
"value":"false;false;false"
}
]
}
]
}
]
}
}
The result 0 tells that the first value "keine Garantie" has been selected in our database. Can i display directly in one cell in the SQL query wich value has been selected?
Here is a example of the best result i could get with my SQL knowledge:
SELECT
JSON_VALUE (REPLACE(Facet.[value], '[', ''), '$.facet.value') as 'Values',
Result.[value] as 'Result'
FROM
CROSS APPLY OPENJSON(JSON_query(JSONCELL, '$.fields.field')) as Result2
CROSS APPLY OPENJSON(Result2.[value], '$') as Result
CROSS APPLY OPENJSON(JSON_query(JSONCELL, '$.fields.field')) as Facet2
CROSS APPLY OPENJSON(Facet2.[value], '$') as Facet
RESULT:
Values "keine Garantie;Garantie;Kulanz"
Result "0"
EDIT: Im after the result "keine Garantie". On the Website wich the data is coming from i can choose from "keine Garantie", "Garantie", "Kulanz". The result 0 is telling that the user choosed "keine Garantie".
Thank you in advance for your help and your answers!