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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Value Output 1

Status
Not open for further replies.

sila

Technical User
Aug 8, 2003
76
GB
Hi
Can anyone tell me how I make the query below give me both return results as I run it now it only shows me the first one?
Thanks

Code:
ALTER PROCEDURE dbo.CES_CheckCountToCloseDown
/**/	(
	
		@ElecID as real
		
	)
	
AS
declare @closedown  int
declare @allresultsin int

	set @closedown =(
	SELECT     COUNT(*) AS CheckCloseDown
	FROM         dbo.Election
	WHERE     (CountToCloseDown IS NULL) AND (ElectionID = @ElecID)
	)
	RETURN  @closedown	
	
	set @allresultsin =(
	SELECT     COUNT(*) AS AllResultsIn
	FROM         dbo.DivElection
	WHERE     (ResultsComplete is NULL and ElectionID = @ElecID)
	)
	

RETURN  @allresultsin
 
you can only return 1 result using RETURN so it wont work as you have tried.
Try either using return parameters as below
Code:
ALTER PROCEDURE dbo.CES_CheckCountToCloseDown
/**/    (
    
        @ElecID as real,
       @po_CloseDown int output,
       @po_allresultsin int output

        
    )
    
AS
declare @closedown  int
declare @allresultsin int

    set @po_CloseDown=(
    SELECT     COUNT(*) AS CheckCloseDown
    FROM         dbo.Election
    WHERE     (CountToCloseDown IS NULL) AND (ElectionID = @ElecID)
    )
    
    set @po_allresultsin=(
    SELECT     COUNT(*) AS AllResultsIn
    FROM         dbo.DivElection
    WHERE     (ResultsComplete is NULL and ElectionID = @ElecID)
    )

or try a select statement.
Code:
ALTER PROCEDURE dbo.CES_CheckCountToCloseDown
/**/    (
    
        @ElecID as real
        
    )
    
AS
declare @closedown  int
declare @allresultsin int

    set @po_CloseDown=(
    SELECT     COUNT(*) AS CheckCloseDown
    FROM         dbo.Election
    WHERE     (CountToCloseDown IS NULL) AND (ElectionID = @ElecID)
    )
    
    set @po_allresultsin=(
    SELECT     COUNT(*) AS AllResultsIn
    FROM         dbo.DivElection
    WHERE     (ResultsComplete is NULL and ElectionID = @ElecID)
    )
SELECT @po_CloseDown
UNION ALL
SELECT @po_allresultsin

"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top