title: while loop select in SQL Server
body: <p>I'm sure this is easy but I'm still getting syntax errors when I run it in SQL Server Management Studio v17.4. </p>
  
  <p>I have table T1 which has serial numbers, and I just need to iterate through  and check how many times they appear in T2. I tried like </p>
  
  <pre><code>declare @serial int
  
  select @serial = select serial from T1
  
  while @serial
  begin
      select count(*) from T2 where Serial = @serial
  end
  </code></pre>
  
  <p>But I get an error:</p>
  
  <blockquote>
    <p>Incorrect syntax near the keyword 'select'</p>
  </blockquote>
  
  <p>How to do it? Thanks. </p>