Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP - Using query results in another query?

Status
Not open for further replies.

sknyppy

Programmer
Joined
May 14, 1999
Messages
137
Location
US
I'm just getting started using stored procedures so this may be a silly question.

In query1 I get a list of ModuleIDs.
In query2 I get the modulenames using the ModuleIDs from query1. Can this be done or do I need to use 2 SPs?

Thanks,
Dave

--------------------
CREATE PROCEDURE spUserPreferences
@Username [varchar] (50),
@ModuleList [varchar] (30) OUTPUT
AS
SELECT Username,ModuleIDs
FROM UserPref
WHERE NTUsername = @Username

SET @ModuleList =spUserPreferences.ModuleIDs

SELECT ModuleName
FROM allModules
WHERE MID IN(@ModuleList)
GO
---------------------
 
Hi,

You can combined as many select statement into one select statement.

Try this out:

SELECT UserName, ModuleIDs, ModuleName
FROM UserPref, allModules
WHERE UserPref.NTUsername = @Username
AND UserPref.ModuleIDs = allModules.MID

Kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top