Connecting Tech Pros Worldwide Help | Site Map

Math SUM() - - Database amounts lack positive / negative

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 01:54 AM
Dig314
Guest
 
Posts: n/a
Default Math SUM() - - Database amounts lack positive / negative

I need to Total the amounts for each Property ID in a table.
All the amounts are stored as positive in the database.
Based on a transaction code, the amount should be added or subtracted.
There are about 14 transaction codes, but here is an example:

Transaction Code "Addition" - - add the amount
Transaction Code "Disposal" - - subtract the amount

Can this be done in single select statement ?

Thank you for your assistance!

Dig

  #2  
Old November 13th, 2005, 01:54 AM
Douglas J. Steele
Guest
 
Posts: n/a
Default Re: Math SUM() - - Database amounts lack positive / negative

As long as you're not going to have to do any updates on the table, create a
Union query that "corrects" the values, and then do your query on that:

SELECT Amount FROM Table WHERE TransactionCode = "Addition"
UNION
SELECT 0 - Amount FROM Table WHERE TransactionCode = "Disposal"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Dig314" <dig314@yahoo.com> wrote in message
news:d7effb67.0408201044.1370b1dc@posting.google.c om...[color=blue]
> I need to Total the amounts for each Property ID in a table.
> All the amounts are stored as positive in the database.
> Based on a transaction code, the amount should be added or subtracted.
> There are about 14 transaction codes, but here is an example:
>
> Transaction Code "Addition" - - add the amount
> Transaction Code "Disposal" - - subtract the amount
>
> Can this be done in single select statement ?
>
> Thank you for your assistance!
>
> Dig[/color]


  #3  
Old November 13th, 2005, 01:54 AM
Pieter Linden
Guest
 
Posts: n/a
Default Re: Math SUM() - - Database amounts lack positive / negative

dig314@yahoo.com (Dig314) wrote in message news:<d7effb67.0408201044.1370b1dc@posting.google. com>...[color=blue]
> I need to Total the amounts for each Property ID in a table.
> All the amounts are stored as positive in the database.
> Based on a transaction code, the amount should be added or subtracted.
> There are about 14 transaction codes, but here is an example:
>
> Transaction Code "Addition" - - add the amount
> Transaction Code "Disposal" - - subtract the amount
>
> Can this be done in single select statement ?
>
> Thank you for your assistance!
>
> Dig[/color]

you mean using a function or something?

Function AddMySign(byval curAmount as Currency, byval
strTransactionCode as string) As Currency

Select Case strTransactionCode
Case "Addition","AnotherAdd"
curAmount=abs(curAmount)
Case "Disposal"
curAmount=-curAmount
end select

or did you mean by nesting IIF statements?
  #4  
Old November 13th, 2005, 01:56 AM
Dig314
Guest
 
Posts: n/a
Default Re: Math SUM() - - Database amounts lack positive / negative

Thank you Doug and Pieter very much.
In this particular instance, a function will work best.
However, a Union statement will come in handy later.

Dig





dig314@yahoo.com (Dig314) wrote in message news:<d7effb67.0408201044.1370b1dc@posting.google. com>...[color=blue]
> I need to Total the amounts for each Property ID in a table.
> All the amounts are stored as positive in the database.
> Based on a transaction code, the amount should be added or subtracted.
> There are about 14 transaction codes, but here is an example:
>
> Transaction Code "Addition" - - add the amount
> Transaction Code "Disposal" - - subtract the amount
>
> Can this be done in single select statement ?
>
> Thank you for your assistance!
>
> Dig[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.