Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Using Temp tables instead of Cursors

Author  Topic 

daniel.newman@bis-web.net
Yak Posting Veteran

71 Posts

Posted - 2001-06-11 : 11:48:35
I know you keep saying "don't use cursors", but I'm going to need some help on how to do a recursive couple of commands on something that resembles very much a cursor.

My SP is currently only assuming it will return one figure from the database, and then action on that, but I need to build in the fact that more than one record may match, so it will have to loop through them.

This is what I have so far:

CREATE PROCEDURE dbo.xxx_RemoveThisUser
@email varchar(100)
AS

DECLARE @UserID int

SELECT @UserID = UserID FROM Users WHERE Email = @email -- only returns one at present

/* potential loop in here*/
DELETE FROM Address WHERE UserID = @UserID
DELETE FROM Institution WHERE UserID = @UserID
DELETE FROM Postcode WHERE UserID = @UserID
DELETE FROM Users WHERE UserID = @UserID
DELETE FROM Users_on_Lists WHERE UserID = @UserID
/* end loop */
GO

So how can I build in a looping code block without using cursors?

Sorry if this is too basic for a monday morning, but there you go :)

Thanks for helping,
Daniel Newman.
   

- Advertisement -