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

Return the number of rows of a sub query in a stored procedure 1

Status
Not open for further replies.

Geee

Programmer
Joined
Apr 23, 2001
Messages
253
Location
GB
Hi folks,

I have the following query that returns the unique rows from a couple of tables...

SELECT DISTINCT GameOptionsMap.Value, GameOptionsMap.PositionID FROM playergamepositionmap
INNER JOIN GameOptionsMap ON (playergamepositionmap.GameID = GameOptionsMap.GameID)
WHERE playergamepositionmap.GameOutcome = 1 AND playergamepositionmap.PlayerID = 27
AND GameOptionsMap.GameOptionID = 2

What I want to do is return the number of rows returned by this query without returning any actual values to the output of the SP. Any ideas greatfully received!

G

-Geeeeeeeeeeeeeeeeeeeeeeee-
 
Code:
ALTER PROCEDURE YourSPName
AS
BEGIN
DECLARE @Rows int
SET @Rows = 0 -- Just in case you didn't have any rows

SELECT @Rows = COUNT(*)
FROM (SELECT DISTINCT GameOptionsMap.Value,
                      GameOptionsMap.PositionID
      FROM playergamepositionmap
          INNER JOIN GameOptionsMap ON
                     (playergamepositionmap.GameID = GameOptionsMap.GameID)
          WHERE playergamepositionmap.GameOutcome =  1 AND
                playergamepositionmap.PlayerID    = 27 AND
                GameOptionsMap.GameOptionID       = 2) Tbl1
RETURN @Rows
END

NOT TESTED !!!!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top