July 15, 2020 at 8:30 pm
Hi,
I have a string that comes into one of my column and I need to create a column for each item.
It looks something like this but much longer
{"Id":"1bban5d82-23g4c-430ui-b804-4c3awasgec28","RecordType":20,"CreationTime":"2020-07-07T03:39:55"}
Thanks
Astrid
July 15, 2020 at 9:57 pm
After adding [] to make this valid JSON, I came up with this
DROP TABLE IF EXISTS #SomeJSON;
CREATE TABLE #SomeJSON
(
JSONString VARCHAR(MAX) NOT NULL
);
INSERT #SomeJSON
(
JSONString
)
VALUES
('[{"Id":"1bban5d82-23g4c-430ui-b804-4c3awasgec28","RecordType":20,"CreationTime":"2020-07-07T03:39:55"}]');
SELECT sj.JSONString
,x.id
,x.RecordType
,x.CreationTime
FROM #SomeJSON sj
CROSS APPLY
(
SELECT *
FROM
OPENJSON(sj.JSONString)
WITH
(
id VARCHAR(100) 'strict $.Id'
,RecordType INT '$.RecordType'
,CreationTime DATETIME '$.CreationTime'
)
) x;
July 16, 2020 at 12:11 pm
thanks!!!
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy