Solved

how can i merag beetween 2 tables in sql ?

Posted on 2006-11-05
1
180 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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.

728 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

10 Experts available now in Live!

Get 1:1 Help Now