I have a column containing multiple values separated by a "," also including the headers separated by a ":". The column looks like this:
{"Id":"c7d45d60-cf90-490d-be4c-f04c9349da03","RecordType":20,"CreationTime":"2018-06-12T21:48:30","Operation":"DownloadReport","OrganizationId":"dabd5d90-87c2-44c9-93cd-783e03236e40","UserType":0,"UserKey":"10033FFF85612C0C","Workload":"PowerBI","UserId":"xxxxxx@grundfos.com","ClientIP":"xxx.3.xx.111","UserAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/66.0.3359.181 Safari\/537.36","Activity":"DownloadReport","ItemName":"My Salesresponsibility Final 12-06-2018","WorkSpaceName":"My Sales Dashboard testing environment","DatasetName":"My Salesresponsibility Final 12-06-2018","ReportName":"My Salesresponsibility Final 12-06-2018","CapacityId":"65CB790D-16C8-4DA6-BFA2-89854100423E","CapacityName":"Hope","WorkspaceId":"34812eed-830a-43b2-ae18-6c5c1c0c92a1","ObjectId":"My Salesresponsibility Final 12-06-2018","DatasetId":"b6184b73-fea2-4244-83ca-328e89c536af","ReportId":"36e6b6c5-ceeb-4d02-9d54-fb820634e839","IsSuccess":true,"DatapoolRefreshScheduleType":"None"}
Is there a way to split these values and their headers into separate columns? So the first column would be named 'Id' and contain the value 'c7d45d60-cf90-490d-be4c-f04c9349da03' and so forth. I have tried following the most upvoted solution to this similar question, but it doesn't seem to work: How to split a comma-separated value to columns
So I want to go from this:
To something like this:
I have tried to use this code, but it really doesn't work well:
SELECT [AuditData]
,Substring(AuditData, 1,Charindex(',', AuditData)-1) as Id
,Substring(AuditData, Charindex(',', AuditData)+1, LEN(AuditData)) as RecordType
,Substring(AuditData, Charindex(',', AuditData)+2, LEN(AuditData)) as CreationTime
FROM [dbo].[Log]