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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored procedure loop through selected records
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 02/28/2013 :  06:11:45  Show Profile  Reply with Quote
Hello All,
I have a little challenge.
I am confronted with a situation where I need a stored procedure that will initially select a group of records by passing some parameters. I am expecting at least three records every time. Now, with the selected records, I want to iterate through them, pick a particular field each time and pass it as a parameter in a different select statement. Then return all the selected results from this iteration.
Any help on this will be appreciated.

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/28/2013 :  06:17:51  Show Profile  Reply with Quote
you dont need a loop

just do like

SELECT fields
FROM secondTable
WHERE Searchfield IN (SELECT LookupField
                      FROM firsttable
                      WHERE your filter conditions...

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000