Solved

how can i merag beetween 2 tables in sql ?

Posted on 2006-11-05
1
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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