Solved

QUERY TO ASSIGN TRANSACTION AMOUNT TO DEBIT OR CREDIT

Posted on 2011-03-10
2
548 Views
Last Modified: 2012-05-11
Hi All,

I have transaction which are :

1. Money Receive.
2. Money Pay.

Query Condition :

1. When Receive then Debet.
2. When Receive and Minus Then Credit

3. When Pay then Credit.
4. When Pay and Minus Then Debit

Below are my code :

CASE WHEN RIGHT(A.TipeTransaksi, 1) = 'D' THEN B.TransactionAmount ELSE 0.00 END AS Debit"
CASE WHEN RIGHT(A.TipeTransaksi, 1) = 'C' THEN B.TransactionAmount ELSE 0.00 END AS Credit"

How to add condition for minus TransactionAmount  to the right place, Debit or Credit?

Thank you.


0
Comment
Question by:emi_sastra
2 Comments
 
LVL 28

Accepted Solution

by:
Ryan McCauley earned 500 total points
Comment Utility
It's a little long, but this would work:


CASE WHEN RIGHT(A.TipeTransaksi, 1) = 'D' AND B.TransactionAmount > 0 THEN B.TransactionAmount
     WHEN RIGHT(A.TipeTransaksi, 1) = 'C' AND B.TransactionAmount < 0 THEN -1 * B.TransactionAmount
     ELSE 0.00
END AS Debit,
CASE WHEN RIGHT(A.TipeTransaksi, 1) = 'C' AND B.TransactionAmount > 0 THEN B.TransactionAmount
     WHEN RIGHT(A.TipeTransaksi, 1) = 'D' AND B.TransactionAmount < 0 THEN -1* B.TransactionAmount
     ELSE 0.00
END AS Credit

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
Comment Utility
Hi ryanmccauley,

It works.

Thank you very much for your help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now