Some calculations on a table

  • 15 years ago

    i have a table with these colums:

    Balance   TransactionAmount   TransactionType        NewBalance

    200          25                                 1                              225

    200         40                                    2                              160

    what i want to do is make a query that will calculate the new balance as follows:

    if the transactionType is 1 it will add the Balance+TransactionAmoun

    if the transactionType is 2 it will get the difference

    please help

  • 15 years ago

    SELECT Balance, TransactionAmount, TransactionType,
    IIf(TransactionType = 1, Balance + TransactionAmount, Balance - TransactionAmount) AS NewBalance FROM TableName

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”