Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Displaying the balance from the amount

Author  Topic 

Kotti
Posting Yak Master

129 Posts

Posted - 2009-11-03 : 05:44:53
Hello Friends,

I have a table called Web_UserAccount where i saved the payment and Purchase details of User.

Table Format
UAId UserId PurchaserId amount TransactionType
1 1 0 100 1
2 2 0 200 1
3 1 4 50 2
4 2 1 30 2
5 1 0 80 3
6 1 0 40 4
7 1 3 20 2

OutPut Structure:
Here i am Passing (UserId=1 or PurchaserId=1 )in where condition
to get the below expected result.

Expected OutPut:
UAId UserId PurchaserId amount TransactionType PStatus Balance

1 1 0 100 1 Credit 100
3 1 4 50 2 Credit 150
4 2 1 30 2 Debit 120
5 1 0 80 3 Debit 40
6 1 0 40 4 Debit 0
7 1 3 20 2 Credit 20

How i got the OutPut is?

If the TransactionType=1 means i need the amount should be added in balance and PStatus should display as Credit
If the TransactionType=2 and UserId=1 means i need the amount should be added in Balance and PStatus should display as Credit
If the TransactionType=2 and Purchaserid=1 means i need the amount should be subtracted in Balance and PStatus should display as Debit
If the TransactionType=3 means i need the amount should be subtracted in balance and PStatus should display as Debit
If the TransactionType=4 means i need the amount should be subtracted in balance and PStatus should display as Debit.

If you need more explanation ,i will explain.

Please anyone help me to get the query .

Thanks in Advance.


Kotti
Posting Yak Master

129 Posts

Posted - 2009-11-03 : 08:28:25
Hello Friends,

Any one Please help me to get the correct query.

Thanks in Advance
Go to Top of Page
   

- Advertisement -