I have what is probably a relatively easy query but I cannot get my head around how to query nested json arrays. I have a SQL 2016 DB with a json field which contains a json string with multiple child arrays.
Attached is an image of the json data:
I would like to query the "identification" data (99999829250103)
I can query data such as the accountId (LOADACC001) or nickname (LoadTest) using the following query but cannot query from the "account" array:
SELECT top 1
accountId as NonUserAccountId
FROM [DBName].DBSchema.transactions t
CROSS APPLY OPENJSON (t.BankDataText, N'$.data')
WITH
(
accountId VARCHAR(100) 'strict $.account.accountId'
)
where t.Id = 675
The field 'BankDataText' contains the json string and the table is called 'transactions'. when I add another CROSS APPLY to the query no rows are returned.