Hi makumbi,
You need to use IDENTITY function to replace the ROW_NUMBER function.
First you need to insert all the record to Temporary table with IDENTITY function for Row number.
Then use the Temporary table to get the column value inside the While loop.
Example
DECLARE @Customers AS TABLE(CustomerID INT, Name VARCHAR(50), Country VARCHAR(50))
INSERT INTO @Customers VALUES(1,'John Hammond','United States')
INSERT INTO @Customers VALUES(2,'Mudassar Khan','India')
INSERT INTO @Customers VALUES(3,'Suzanne Mathews','France')
INSERT INTO @Customers VALUES(4,'Robert Schidner','Russia')
SELECT IDENTITY(INT,1,1) RowId, CustomerID, Name, Country
INTO #Results
FROM @Customers
DECLARE @Id INT, @Name VARCHAR(50)
SET @Id = (SELECT CustomerID FROM #Results t WHERE t.RowId = 1)
SET @Name = (SELECT Name FROM #Results t WHERE t.RowId = 1)
SELECT @Id 'Id', @Name 'Name'
DROP TABLE #Results
Output
Id Name
1 John Hammond