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
 Transact-SQL (2000)
 select statement

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2002-02-26 : 13:18:42
How can I bring back all rows of 1 userID, 1 userID at a time.

For example I would like to bring back 2 rows of 497 first, then next time it would be run it would bring back 680 all three rows. (after I delete the previous ID of course)


UserID ThumbID

497 1
497 2
680 2
680 1
680 3
1111 2
1111 1
1111 3
1268 2
1268 1
1268 3
1562 3


Thanks guys!

Edited by - mike123 on 02/26/2002 13:19:07

lfmn
Posting Yak Master

141 Posts

Posted - 2002-02-26 : 13:45:33
Why not use a cursor? (don't tell nr)

declare @userid int
Declare userid_cursor CURSOR FOR

select distinct userid from table1

OPEN userid_cursor

FETCH NEXT FROM userid_cursor into @userid
WHILE @@FETCH_STATUS = 0
BEGIN

select * from table1 where userid = @userid

/*
process your data
*/

delete table1 where userid = @userid

FETCH NEXT FROM userid_cursor into @userid

END

CLOSE userid_cursor
DEALLOCATE userid_cursor


SQL is useful if you don't know cursors :-)
Go to Top of Page
   

- Advertisement -