I have a stored procedure that I am using to extract values from a JSON column in a table:
@ReferenceID int,
@BureausID int,
@EmployersID int,
@FileType varchar(12),
@TargetIndex int
Code:
SELECT
SalesOrderJsonData.*
FROM
MapHistories AS Tab
CROSS APPLY
OPENJSON(Tab.MapJSON, N'$.Mapping')
WITH
(
ReferenceNumber int N'$.ReferenceNumber',
target_field nvarchar(max) N'$.TargetField[@TargetIndex].field',
output_field_description nvarchar(max),
N'$.TargetField['@TargetIndex'].output_field_description',
I need to be able to pass in the target index, as there are multiple records in this JSON array. I am at a loss and not sure how to pass the param into the JSon path successfully.