I hope I understand this correctly. You need to parse the JSON, stored in details column and return the content as a table using OPENJSON(). The next example demonstrates how to use OPENJSON() with one table (note, that the JSON in the question is not correct):
Table:
CREATE TABLE Events (
id int,
details nvarchar(max)
)
INSERT INTO Events (id, details)
VALUES (1, N'{"items":[{"ids":[51130]}]')
Statement:
SELECT id, itemId
FROM Events
CROSS APPLY OPENJSON(details, '$.items[0].ids') WITH (itemId int '$')
Result:
----------
id itemId
----------
1 51130
For complex statements, you may try to use the appropriate joins to get the expected results.
Tables:
CREATE TABLE Brands (
brandId int,
brandName nvarchar(100)
)
INSERT INTO Brands
(BrandId, BrandName)
VALUES
(1, N'Apple'),
(2, N'Samsung')
CREATE TABLE Items (
id int,
name nvarchar(50),
description nvarchar(50),
brandId int
)
INSERT INTO Items
(id, name, description, brandId)
VALUES
(51130, N'Galaxy 10', N'Smartphone', 2)
CREATE TABLE Events (
id int,
details nvarchar(max)
)
INSERT INTO Events
(id, details)
VALUES
(1, N'{"items":[{"ids":[51130]}]')
Statement:
SELECT *
FROM Brands b
INNER JOIN Items i ON b.brandId = i.BrandId
INNER JOIN (
SELECT id, itemId
FROM Events
CROSS APPLY OPENJSON(details, '$.items[0].ids') WITH (itemId int '$')
) e ON i.id = e.itemId
Result:
----------------------------------------------------------------------
brandId brandName id name description brandId id itemId
----------------------------------------------------------------------
2 Samsung 51130 Galaxy 10 Smartphone 2 1 51130