Help with SQL query and Stored Procedure

  • mike 69307 (10/1/2011)


    So i need to bring the create table to the top above the select statements, and then add this to the select statements?

    t.finalplace , t.totalpoints

    FROM vwFullPlayerInfo fpi

    join @Tmp t on fpi.userid = t.userid

    is that what you are saying? How would i add it to the select statements? BTW, thanks for your help, it is much appreciated!

    Something like this should work:

    ALTER PROCEDURE [dbo].[hc_fullrankingsexport]

    -- Add the parameters for the stored procedure here

    @portalid int,

    @venueid int = null,

    @fromdate datetime,

    @todate datetime,

    @regionid int = null

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    declare @Tmp table (rank int ,userid int, fullname nvarchar(150), firstplace int, secondplace int, thirdplace int, finalplace int, totalpoints int)

    insert into @Tmp

    exec ppmsplayerReport @portalid = @portalid, @fromdate = @fromdate, @todate = @todate,

    @venueid = @venueid, @regionid = @regionid, @fullname = ?????

    -- Insert statements for procedure here

    if @venueid IS NULL

    SELECT fpi.UserID, Username, FirstName, LastName, Email, PokerRegion, Street, State, PostalCode, City, finalplace , totalpoints FROM vwFullPlayerInfo fpi

    join @Tmp t on fpi.userid = t.userid

    WHERE (fpi.UserID IN (SELECT userid FROM PPMSPoints WHERE (matchdate BETWEEN @fromdate AND @todate ))) ORDER BY FirstName

    IF @venueid IS NOT NULL

    SELECT fpi.UserID, Username, FirstName, LastName, Email, PokerRegion, Street, State, PostalCode, City, finalplace , totalpoints FROM vwFullPlayerInfo fpi

    join @Tmp t on fpi.userid = t.userid

    WHERE (fpi.UserID IN (SELECT userid FROM PPMSPoints WHERE venueid = @venueid AND (matchdate BETWEEN @fromdate AND @todate ))) ORDER BY FirstName

    END

    That should be pretty close.

    Ben

  • It looks like it worked. I have been studying what you did here. I will learn from it, thanks!

  • Glad you got it working.

    Ben

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply