Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Questions

Status
Not open for further replies.

lah3233

MIS
Jul 15, 2003
33
US
I have a programmer that would like to be able to pull information out of a table one row at a time. I know that cursors are performance killers and not a good option...I'm just not sure if there is any other way to do this. The cursor we have now pulls out the info one row at a time...but lists all of them.

DECLARE Login_Cursor CURSOR FOR
SELECT strLoginName FROM LoginInfo
OPEN Login_Cursor
FETCH NEXT FROM Login_Cursor
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Login_Cursor
END
CLOSE Login_Cursor
DEALLOCATE Login_Cursor

Does anyone out there have a solution or other ideas as how to approach this problem?

Thank you!
 
If you want to avoid cursor ,but want to do a task exactly like cursor.You may use create a temptable with only the column which is needed and a id or counter column (autoincremented),then do the loop instead

select identity(int,1,1) as id,strLoginName into #temp from
LoginInfo

declare @id int
set @id = 1
while @id <=(select count(*) from #temp)
begin


set @id = @id +1
end

This will loop the whole table till the end.
Hope it help!

 
Thanks for the help. If you want to update the original table...how do you go about doing that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top