Solved

how can i merag beetween 2 tables in sql ?

Posted on 2006-11-05
1
181 Views
Last Modified: 2012-06-27
hi there , i have a Financial software in the Db i have 2 tables

invoice table
receipt  table

i have a cust that have 2 invoice and 1 receipt
i want to get the balance

i need to get all the invoice  sum and get all the receipt sum as well to calculate the his balance

but i need to see the actions like in the bank
invoice    balance
-500        -500
-500       -1000
500(receipt) so his balance is  -500
i am on c# dot net 1.0 WinForms App.
thanks ....


       

0
Comment
Question by:Tech_Men
1 Comment
 
LVL 6

Accepted Solution

by:
so3 earned 500 total points
ID: 17875886
Create a view that will calculate the sum of the invoice and of the receipt and the made a relation between them

e.g
let's say that we have this tables:

Invoice table        
ID
ID_CUSTOMER
INV_VAL

and

Receipt table  
ID      
ID_CUSTOMER
REC_VAL

The view should look like something like this:

SELECT ID_CUSTOMER, SUM(INVOICE) as INVOICE, SUM(RECEIPT) as RECEIPT, SUM(INVOICE)-  SUM(RECEIPT) as BALANCE
FROM

(SELECT        ID_CUSTOMER, SUM(INV_VAL) AS INVOICE, 0 AS RECEIPT
FROM            INVOICE
GROUP BY ID_CUSTOMER
UNION
SELECT        ID_CUSTOMER, 0 AS INVOICE, SUM(REC_VAL) AS RECEIPT
FROM            RECEIPT
GROUP BY ID_CUSTOMER) BAL_VIEW

GROUP BY ID_CUSTOMER


The view will show ID_CUSTOMER, INVOICE,RECEIPT and BALANCE.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 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