From last two days i am searching for the answer of this querry.
I want to know how can i access the rows of tables in stored procedures using loops(Without cursor).
We don't want to use cursor for that because of the performance issues.

Recommended Answers

All 3 Replies

Just to a while loop.

declare @rowcount int,
@counter int
select @rowcount = (select count(*) from table_name)

set @counter = 0
while @counter <= @rowcount
begin
select * from table_name where rowid = @counter
set @counter = @counter + 1
end

Just to a while loop.

declare @rowcount int,
@counter int
select @rowcount = (select count(*) from table_name)

set @counter = 0
while @counter <= @rowcount
begin
select * from table_name where rowid = @counter
set @counter = @counter + 1
end

MY REPLY:
What was rowid here. It was giving invalid column name in SQL SERVER. PLZ reply soon.

MY REPLY:
What was rowid here. It was giving invalid column name in SQL SERVER. PLZ reply soon.

your auto-incrementing id field

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.