title: SQL Server cursor is not looping although there are lots of records in the table
body: <p>Although <code>SELECT id, also FROM names WHERE isnull(also,'')&lt;&gt;''1</code> is returning 2000+ results, the following cursor not looping and I'm getting:</p>
  
  <pre><code>@count = 0
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>DECLARE @id BIGINT, @name NVARCHAR(1000)
  
  DECLARE @aslo TABLE (id INT, name NVARCHAR(100))
  
  DECLARE name_cur CURSOR FOR 
       (SELECT id, also 
        FROM names 
        WHERE ISNULL(also, '') &lt;&gt; '')
  
  DECLARE @count INT = 0
  
  OPEN name_cur
  
  WHILE @@FETCH_STATUS = 0  
  BEGIN  
     SET @count = @count + 1
  
     INSERT INTO @aslo (id, name)
         SELECT @id, * 
         FROM string_split(@name, ',')
  
     FETCH NEXT FROM name_cur INTO @id, @name;  
  END  
  
  CLOSE name_cur;  
  DEALLOCATE name_cur;
  
  SELECT @count
  SELECT COUNT(*) FROM @aslo a
  </code></pre>