SUM

  • -------|----------------|-----------|--------------|------------|

    UserID |TransactionType |SaleAmount |PaymentAmount |PaymentType |

    -------|----------------|-----------|--------------|------------|

    209541 |Executive 3 year| 6200 | | |

    -------|----------------|-----------|--------------|------------|

    209541 | | | 3000 | Visa |

    -------|----------------|-----------|--------------|------------|

    209541 | | | 3200 | Amex |

    -------|----------------|-----------|--------------|------------|

  • 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

  • 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

  • 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