Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SUM negative amount
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00527742
Message ID:
00527828
Views:
32
Post this in the SQL Server Forum and Mike Levy will probably have an answer for you.

>select sum(Amount * iif(Amount < 0, 1, 0)) as Credit, sum(Amount * iif(Amount > 0, 1, 0)) as Debit from SomeTable where some_condition

>Actually i want to sum negative amounts (Credits) And Positive Amounts (Debits)
>A bit like your example, my statement for VFP table would be like yours:
>
>
>select sum(Amount * iif(Amount < 0, 1, 0)) as Credit, sum(Amount * iif(Amount > 0, 1, 0)) as Debit from SomeTable where some_condition
>
>This works fine with VFP Tables but i am looking for an SQL Server 2000 statement.
>
>Thanks
>
>>>Anybody knows how i could sum all Credit and debit amount in an SQL2000 Table and get the result separated in the same cursor.
>>>
>>>Thanks
>>
>>A little more info please. Do you have a field that contains the transaction type that indicates if the record is a Credit, debit, etc.? You want the credits total separated from the debits total?
>>
>>select sum(credit * iif(TransType = "C", 1, 0)) as Credit, sum(debit * iif(TransType = "D", 1, 0)) as Debit from SomeTable where some_condition
Mark McCasland
Midlothian, TX USA
Previous
Reply
Map
View

Click here to load this message in the networking platform