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 2005 Forums
 Transact-SQL (2005)
 Stored procedure loop through selected records

Author  Topic 

ddombadoh
Starting Member

7 Posts

Posted - 2013-02-28 : 06:11:45
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

52326 Posts

Posted - 2013-02-28 : 06:17:51
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
   

- Advertisement -