sql server - How can I loop through a json array in sql to select a value at a specific index -


i have stored procedure query database , store result in json variable. want loop through json array index specific value. can tell me how achieve this. below query

 declare @json nvarchar(max)  declare @name varchar(50) = 'name'   set @json = (select name getalldataview   soundex(name) soundex(@name) json path, root('names'))   declare @i int = 0   while @i < lengthofarray  begin        set @i = @i + 1;     select value    openjson(@json, '$.names[',@i,']');   end 

when begin end query select openjson , add 1 more column , , value looping index. can add validation inside begin end . openjson read json , insert new row.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -