My initial table looks like this (values of object are dynamic so it's not always the same structure):
id tags
1 {"tag1": "value1"}
2 {"tagA": "valueA", "tagB": "valueB"}
And I want to transform it into this:
id tag value
1 tag1 value1
2 tagA valueA
2 tagB valueB
Could anyone help me with the transformation? I tried using OPENJSON like this but it only works if I filter by id (plus I'm not getting the id column in the result):
DECLARE @json NVARCHAR(MAX)
SET @json = (SELECT tags from auxTagsResources where instanceId = 1)
SELECT \[key\] as tagName, value as tagValue FROM OPENJSON(@json);
Result:
tagName tagValue
tag1 value1