title: Deleting the element with the given id from the json array by navigating all the tables in SQL Server
body: <p>All tables have a common column called <code>BranchList</code>. <code>BranchList</code> is a string containing a json array, like this</p>
  <pre><code>[ { &quot;Id&quot;: 1, &quot;Branch&quot;: 259 }, { &quot;Id&quot;: 1, &quot;Branch&quot;: 253 } ]
  </code></pre>
  <p>I want to remove the json value which is branch 253 from the list by navigating all the tables, It should be like this</p>
  <pre><code>[ { &quot;Id&quot;: 1, &quot;Branch&quot;: 259 } ]
  </code></pre>
  <p>I found a method for a single table like this but it's not enough for me to update all tables.</p>
  <pre><code>declare @JSONData nvarchar(max)
  declare @Id nvarchar(max)
  declare @BranchList nvarchar(max)
  declare @Counter INT
  
  select @Counter = count(BranchList) 
  from WarehouseTypes 
  outer apply OPENJSON(BranchList) as s
  where JSON_VALUE(s.value,'$.Branch') = 253;
  
  while (@Counter &gt; 0)
  begin
      select @Id = Id, @BranchList = BranchList 
      from WarehouseTypes 
      outer apply OPENJSON(BranchList) as s
      where JSON_VALUE(s.value,'$.Branch') = 253;
     
      set @JSONData = N''+@BranchList+'';
      set @JSONData = (select * 
                       from OPENJSON(@JSONData, '$') 
                       with (
                             Id int '$.Id',
                             Branch int '$.Branch'
                            )
                       where not (Branch = 253) 
                       for json path);
     
      exec('update WarehouseTypes set BranchList ='''+@JSONData+''' where Id='+@Id);
      set @Counter = @Counter  - 1
  end
  </code></pre>
  <p>Thank you in advance for your help.</p>