-1

I am trying to parse JSON and pass the key-value pairs into a stored procedure.

declare @json nvarchar(max) = '{"bin":1,"type":"A"}',
@id int = 1234

exec someStoreProcedure select 
json_value(@json, '$.bin'), 
json_value(@json, '$.type'),
@id

How can I pass in json_values to a stored procedure?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Matthew
  • 1,461
  • 3
  • 23
  • 49
  • 3
    You would have to assign the to variables first; you cannot pass expressions to a Stored Procedure parameter. – Thom A Nov 23 '20 at 19:04

1 Answers1

0
-- Inputs

declare @json nvarchar(max) = '{"bin":1,"type":"A"}',
@id int = 1234

-- Map json to variables

declare @bin int = json_value(@json, '$.bin')
declare @type nvarchar(10) = json_value(@json, '$.type')

-- Pass variables into procedure

exec someStoreProcedure select 
@bin, 
@type,
@id
Matthew
  • 1,461
  • 3
  • 23
  • 49