Hey,
I have a database that holds a list of figures combined with a open date and an end date. I need to grab a SUM of all the figures whereby the end date falls within a set date range.
I need this as a stored procedure where by I can pass the userid in 'foreign key' and 2 dates to get a sum of all the figures that falls in this. Currently my procedure looks like (I know its wrong) might give you an idea what I am after
Help me please!
The database is called goldmine, the table is called opmgr.
--------------------------------------------
CREATE PROCEDURE dbo.MikeProfitCheck ( @userID nvarchar, @BDate DateTime, @EDate DateTime)
AS
DECLARE @amount int;
SELECT @amount=sum(Opmgr.closeamt)
FROM Opmgr
WHERE
Opmgr.userid = @userID
AND
Opmgr.status='won'
AND Opmgr.closeddate BETWEEN @BDate AND @EDate
RETURN @amount
GO
--------------------------------------------
Thanks in advance!
Mike
I have a database that holds a list of figures combined with a open date and an end date. I need to grab a SUM of all the figures whereby the end date falls within a set date range.
I need this as a stored procedure where by I can pass the userid in 'foreign key' and 2 dates to get a sum of all the figures that falls in this. Currently my procedure looks like (I know its wrong) might give you an idea what I am after
Help me please!
The database is called goldmine, the table is called opmgr.
--------------------------------------------
CREATE PROCEDURE dbo.MikeProfitCheck ( @userID nvarchar, @BDate DateTime, @EDate DateTime)
AS
DECLARE @amount int;
SELECT @amount=sum(Opmgr.closeamt)
FROM Opmgr
WHERE
Opmgr.userid = @userID
AND
Opmgr.status='won'
AND Opmgr.closeddate BETWEEN @BDate AND @EDate
RETURN @amount
GO
--------------------------------------------
Thanks in advance!
Mike