I have a table that has three columns from which I need to retrieve the data. One of the columns OtherNames contain an array of Json Objects.
CREATE TABLE Persons (
NameID int,
CurrentName varchar(255),
OtherNames varchar(max),
);
I can query that column just fine, but how can I join it with the table it is in by ID so I can retrieve all the information on the table and what is related to this row.
DECLARE @test VARCHAR(MAX)
SELECT @test = '[{"Name":"Bob","DateTime":"03/03/2022"},{"Name":"Adam","DateTime":"04/05/2022"}]'
SELECT * FROM OPENJSON(@test)
WITH (
Name VARCHAR(MAX) '$.Name',
DateTime VARCHAR(MAX) '$.DateTime'
)
This above results in
Bob 03/03/2022
Adam 04/05/2022
How can I join to show the NameID and CurrentName along with it ?
NameID Name DateTime CurrentName
1 Bob 03/03/2022 Rob
1 Adam 04/05/2022 Rob
There could be multiple records and multiple Json data..