|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'm trying to write a nested stored procedure, with the outer proc named "spAssociate", and inner proc named "spSales". So far I have created the inner proc CREATE PROCEDURE spSales @userID intAS SET NOCOUNT ONGO This was successfully created. I wanted to use the return set in the outer proc, which I tried creating as: CREATE PROCEDURE spAssociate (@userID int,AS SET NOCOUNT ONGO I get an error "incorrect syntax near execute". How can I use the results from the inner proc for the WHERE condition in my outer proc? Any help is greatly appreciated. Thanks! |
|
#2
|
|||
|
|||
|
What I would suggest is doing Dynamic SQL here. As in let spSales return a OUTPUT variable or something that has all the ids in a comma seperated list, then in your spAssociate place that whole select statement in a varchar variable and append the return variable value you get when executing the spSales proc... something like below might work as an example.
Now, this is just a rough draft but it should give a possible idea of how to over come this problem using Dynamic SQL. =========== Brandon Russell SQL Monkey |
|
#3
|
|||
|
|||
|
Stay away fro dynamic SQL. It is more efficient to join the tables directly.
Code:
SELECT AssociateID
FROM AppRelations
WHERE ContainerType=@containerType
AND ContainerID IN (
SELECT SalesOppID
FROM Sales_Opportunities
WHERE SalesOppCurrentStatus NOT IN ('Sale Lost','Sales Closed','Sale Closed','Unqualified','Deferred','Dropped')
AND OppOwnerUserID = @userID)
AND AssociateType=@associateType
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Using results from stored procedure in WHERE condition |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|