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
Post a Comment