SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

ddombadoh
Starting Member

Ghana
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.
Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52317 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000