title: Printing all values of two columns in sql stored procedure
body: <p>I have been trying to print all values of two columns of table using loop in sql stored procedure but no luck yet.</p>
  
  <pre><code>CREATE PROCEDURE [usp_my_procedure_name]
  AS 
      SET NOCOUNT ON;
  BEGIN
      DECLARE @User_ID INT =16  
      DECLARE @ID INT
      DECLARE @Count INT
      DECLARE @Count1 INT
      DECLARE @Code VARCHAR(500)
  
      SELECT @Count1= MAX(ID), @Count = MIN(ID)
      FROM ABC
      WHERE ID = 10 AND Code NOT LIKE '%ABC%' 
  
      WHILE (@Count &lt;= @count1)
      BEGIN
          SELECT @ID = (ID), @Code = Code 
          FROM ABC 
          WHERE ID = 10 AND Code NOT LIKE '%ABC%
  
          PRINT @ID 
          PRINT @Code
  
          SET @Count = @Count + 1
      END
  END
  </code></pre>
  
  <p>Also how to optimize it further as i have to traverse for 7k records</p>