Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Group BY and Dates

Author  Topic 

Geneoh
Starting Member

4 Posts

Posted - 2004-07-08 : 17:24:51
Hi all,

I am need of some of your collective expertise.

I have a table with the following fields

MemberID
TransDate
Amount

I need to use a stored procedure to pull a SUM(amount) For a date range from parameters such as TRansDate >=@startDate and TRansDate <=@endDate .

My problem is that this keeps breaking on each individual date so that I end up with a Sum of amount for each date in the date range. I need it to not break on each date so that I can then sort on the Sum(amount) Expression this is to allow my to get a high spender result for the time period in question.

Any help would be greatly appreciated


Gene

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-07-08 : 18:19:26
Something like:

SELECT MemberID,SUM(Amount) TTL_Amount
FROM
(
SELECT
MemberID,
TransDate,
Amount
FROM
Table
WHERE
TransDate between @startdate and @enddate
) d
GROUP BY MemberID

) d[/code]
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-07-08 : 18:24:53
select memberid, sum(amount) ttl_amount
from table
where transdate between @startdate and @enddate
group by memberid
Go to Top of Page
   

- Advertisement -