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.
Author |
Topic |
igor22
Starting Member
18 Posts |
Posted - 2006-03-02 : 14:07:29
|
Can you look over the values of a select statment using the while loop? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-03-02 : 14:09:48
|
Yes. If you post the code, we can help.Tara Kizeraka tduggan |
|
|
igor22
Starting Member
18 Posts |
Posted - 2006-03-02 : 14:20:38
|
Ok but please forgive me I'm very new at this: CREATE PROC GetUsersItems( ASDeclare @HoldIds int,SET @HoldIds=Select userid from usersWHILE (@HoldIds)-- Values from the querySelect * From items where userid =@HoldIdsENDGo |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-03-02 : 14:37:30
|
This should get you going:Declare @HoldIds intSelect @HoldIds = MIN(userid)from usersWHILE (@HoldIds <= select max(userid) from users)begin Select * From items where userid =@HoldIds Select TOP 1 @HoldIds = userid FROM users WHERE userid >= @HoldIds ORDER BY useridEND The key is that @HoldIds can only hold one value at a time, so you must loop through the table.Tara Kizeraka tduggan |
|
|
igor22
Starting Member
18 Posts |
Posted - 2006-03-02 : 14:49:19
|
Thanks a lot! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-03 : 01:43:38
|
Is using Join enough?Select I.* From items I inner join Users U on I.Userid=U.userIdMadhivananFailing to plan is Planning to fail |
|
|
|
|
|