De volgende tabel tabel structuur heb ik:
product_id, F010, F020, F030
11, 'Waarde-A', 'Waarde-B', 'Waarde-C'
56, 'Waarde-D', 'Waarde-E', 'Waarde-F'
Wat ik zou willen is de resultaten getransformeerd te hebben naar:
product_id, [key], [value]
11, 'F010', 'Waarde-A'
11, 'F020', 'Waarde-B'
11, 'F030', 'Waarde-C'
etc.
Wat heb ik geprobeerd:
Declare @YourTable Table ([ID] varchar(50),[Col1] varchar(50),[Col2] varchar(50))
Insert Into @YourTable Values
(1,'A','B')
,(2,'R','C')
,(3,'X','D')
Select A.[ID]
,Item = B.[Key]
,Value = B.[Value]
From @YourTable A
Cross Apply ( Select *
From OpenJson((Select A.* For JSON Path,Without_Array_Wrapper ))
Where [Key] not in ('ID','Other','Columns','ToExclude')
) B
product_id, F010, F020, F030
11, 'Waarde-A', 'Waarde-B', 'Waarde-C'
56, 'Waarde-D', 'Waarde-E', 'Waarde-F'
Wat ik zou willen is de resultaten getransformeerd te hebben naar:
product_id, [key], [value]
11, 'F010', 'Waarde-A'
11, 'F020', 'Waarde-B'
11, 'F030', 'Waarde-C'
etc.
Wat heb ik geprobeerd:
Declare @YourTable Table ([ID] varchar(50),[Col1] varchar(50),[Col2] varchar(50))
Insert Into @YourTable Values
(1,'A','B')
,(2,'R','C')
,(3,'X','D')
Select A.[ID]
,Item = B.[Key]
,Value = B.[Value]
From @YourTable A
Cross Apply ( Select *
From OpenJson((Select A.* For JSON Path,Without_Array_Wrapper ))
Where [Key] not in ('ID','Other','Columns','ToExclude')
) B