Replace cursor with while loop in sql.


Declare @count int;
set @count =1;

Declare @loop int;
declare @tempItem_Id bigint;
select @loop = COUNT(item_id_big) from tbl_item_master;


while @count <= @loop
begin
 WITH MyCte AS
(
    select   item_id_big,
             RowNum = row_number() OVER ( order by item_id_big )
    from     tbl_item_master
)
 select @tempItem_Id = item_id_big from MyCte where RowNum = @count;

 print convert(varchar(15), @tempItem_Id)+ ' '+ convert(varchar(4),@count)  + ' \n ';
 set @count = @count+1;
end

Comments

Popular posts from this blog

sp_addmessage can be used to create a User-Defined Error Message

Command-line Building With csc.exe

Prepare DTO layer by using below script