title: Update one column based on the compare values between two different columns
body: <p>I have telephone number code like this:</p>
  
  <p>Table1</p>
  
  <pre><code>rownum TelephoneCode --TelephoneCode is integer datatype
  -------------------        
    1       444
    2       555
    3       666
    4       777
  </code></pre>
  
  <p>I have another table having 3 columns(and country column is blank)</p>
  
  <p>table2</p>
  
  <pre><code>  rownum country telephonenumber -- telephonenumber is varchar datatype
    -------------------------------
      1                 6661234(C)
      2                 4440987
      3                 9999870
      4                 555-1245
  </code></pre>
  
  <p>What I want is, my query should read the "TelephoneCode" from "Table1" and search that code in "tepephonenumber" column in "table2".
    If the "TelephoneCode" is found in "Table2" then update the "Country" column of "Table2" to "AU".</p>
  
  <p>Hence my final table (i.e. table2) result should come like this:</p>
  
  <p>Table2</p>
  
  <pre><code>  rownum country telephonenumber
    -------------------------------
      1        AU         6661234
      2        AU         4440987
      3                   9999870
      4        AU         5551245
  </code></pre>
  
  <p>Here is what I have tried. This query is executing successfully; however, not updating the "Country" Column of "Table2"</p>
  
  <pre><code> declare @code int
   declare @parsedcode int
   declare @numcount int
   declare @numcount1 int
   declare @telephonenumberread varchar(max)
  
  
  
   while(@numcount &lt;= 356)
   begin
  
  
     select @code= [TelephoneCode] from table1 where rownum = @numcount
   --select @code
  
   while(@numcount1 &lt;=137992)
     begin
       select @telephonenumberread = TELPHONH from table2 where rownum = 
       @numcount1
     --print @telephonenumberread
     set @parsedcode = substring(@telephonenumberread,1,3)
  
     if(@code = @parsedcode)
       begin
  
           update table2 set country = 'AU'
           --return
       end
    --else
  
       set @numcount1 = @numcount1+1
  
   end
  
     set @numcount = @numcount+1
  end
  </code></pre>
  
  <p>Hope I have explained it correctly.
  Note:My table has more than 100K blank in the country column.</p>
  
  <p>How to achieve this? Even, Im unable to print the values for the debug? What am I doing wrong?
    Thanks.</p>