Solved

how can i merag beetween 2 tables in sql ?

Posted on 2006-11-05
1
183 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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