I have a JSON string as follows:
DECLARE @json nvarchar(max)
SET @json = '{"value": [
{
"AEDAT": "20211110"
},
{
"AEDAT": "20211110"
},
{
"AEDAT": "20211110"
},
{
"AEDAT": "20211112"
},
{
"AEDAT": "20211112"
},
{
"AEDAT": "20211112"
}
]}';
Now I want to read this JSON in SQL Server using OPENJSON()
and find the MAX value for each AEDAT
. For this, I am using the following query:
SELECT MAX(value)
FROM OPENJSON(@json, '$.value')
The above query is returning a row with key value pair as below:
{"AEDAT":"20211112"}
My objective is to get only 20211112
as integer.
How to achieve this?