 <p>I think there is no need to use cursor here . first you have to select PERSON.ID of those rows only where we have CA in RentedhouseDetails like</p> <pre><code>select p.id from Person p JOIN RentedHousesDetail r ON p.ID=r.ID where r.HouseLocation='CA' </code></pre> <p>then insert all that record into CALIFORNIAHOUSE and STATUSGREEN table </p> <p>Like this</p> <pre><code> Insert into CALIFORNIAHOUSE select p.id from Person p JOIN RentedHousesDetail r ON p.ID=r.ID where r.HouseLocation='CA' </code></pre> <p>AND</p> <pre><code>Insert into STATUSGREEN select p.id from Person p JOIN RentedHousesDetail r ON p.ID=r.ID where r.HouseLocation='CA' </code></pre> <p>AND Finally Update table RentedHousesDetail where HouseLocation='CA' as 'NO'</p> <p>like this</p> <pre><code>update RentedHousesDetail set ISOK='NO' from Person p JOIN RentedHousesDetail r ON p.ID=r.ID where r.HouseLocation='CA' </code></pre>