May 19, 2005 at 12:59 pm
-------|----------------|-----------|--------------|------------|
UserID |TransactionType |SaleAmount |PaymentAmount |PaymentType |
-------|----------------|-----------|--------------|------------|
209541 |Executive 3 year| 6200 | | |
-------|----------------|-----------|--------------|------------|
209541 | | | 3000 | Visa |
-------|----------------|-----------|--------------|------------|
209541 | | | 3200 | Amex |
-------|----------------|-----------|--------------|------------|
May 19, 2005 at 1:19 pm
Try modifing this query as it seems to do the trick from what I see... but I still think that there's a missing column here, but I don't know your system so it's hard to say form here.
Select userId
--, OrderId --if necessary
, sum(SaleAmount - PaymentAmount) as Balance from dbo.YourTable
group by
UserId
--, OrderId --if necessary
May 19, 2005 at 1:28 pm
This is just a guess ...
select dt.TransactionType , SUM (dt.S) as SaleAmount , SUM(dt.P) as PaymentAmount , SUM(dt.S - dt.P) AS Balance
FROM (
Select UserID ,TransactionType, Sum(SaleAmount) as S, Sum(PaymentAmount) as P
FROM dbo.Transactions Where UserID = @ClientID
group by UserID , TransactionType ) dt
group by dt.TransactionType
* Noel
May 19, 2005 at 2:18 pm
I will just use two stored procedures to get the results I need
Thank you anyway
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply