while loop in sql query

select distinct rowid=IDENTITY(Int, 1,1),  buyorder.Chln into #temp from BuyOrder  inner join rChallan  on BuyOrder.Chln=rChallan.OrderNo
where BuyOrder.Qty=BuyOrder.sQty/2 and BuyOrder.sQty=rChallan.Qty

declare @challanID as varchar(50)
declare @num as int
set @num=1

while(@num<=(select MAX(rowid) from #temp))
begin

set @challanID=(select Chln  from #temp  where rowid=@num )
print @challanID

set @num=@num+1

end

drop table #temp

Comments

Popular posts from this blog

How to use DbFunctions.TruncateTime

Provision AWS EC2 Instance and RDS with Terraform, and Deploy Spring Boot App to EC2 Instance via GitHub Action Pipeline

Microsoft Access Connectivity from C#