title: syntax error in SELECT statement
body: <p>With my limited SQL knowledge, I'm unable to figure this out. What's wrong with the following:</p>
  
  <pre><code>DECLARE @Id int
  DECLARE @Name varchar(40)
  
  WHILE EXISTS
          (
          SELECT TOP 1 @Name = Name, @Id=ID FROM MyTable c WHERE &lt;CONDITION&gt;
          )
  BEGIN
      SOME MORE SQL using @Id and @Name
  END
  </code></pre>
  
  <p>I get a syntax error near <code>@Name = Name</code></p>
  
  <h2>EDIT</h2>
  
  <p>To add more context to the problem, I have two tables named <code>Category (ID, Name, ParentID)</code> and <code>Account(ID, Name, CategoryID)</code>. </p>
  
  <p>There are 3 levels of <code>Categories</code>. </p>
  
  <ol>
  <li>Root</li>
  <li>Category</li>
  <li>SubCategory</li>
  </ol>
  
  <p>This is achieved using a recursive relation (<code>ParentID</code> > <code>CategoryID</code>). Problem to solve is that if there are any <code>Accounts</code> that belongs to a Category X (level 2), we must </p>
  
  <ol>
  <li>Create a SubCategory Y (level 3) with the same name as X</li>
  <li>Make Y a child of that X</li>
  <li>Move all Accounts from X to Y</li>
  </ol>
  
  <p>Here is the original script I have written:</p>
  
  <pre><code>DECLARE @Id int
  DECLARE @Name varchar(40)
  
  WHILE EXISTS(
          SELECT TOP 1 @Name=Name, @Id=CategoryID FROM Category c WHERE 
          ParentID = (SELECT TOP 1 CategoryID FROM Category WHERE Name = 'Root') AND
          (SELECT COUNT(*) FROM Account WHERE CategoryID = c.CategoryID) &gt; 0
          )
  BEGIN
      INSERT INTO Category(Name, ParentID) VALUES(@Name, @Id)
      UPDATE Account SET CategoryID = @@IDENTITY WHERE CategoryID = @Id  
  END
  </code></pre>