Mohan Chandra

Mohan Chandra

  • NA
  • 101
  • 16.9k

How check the amount of invoices and receipt is equal inSQL

Jul 7 2016 7:48 AM
Hi, I am using SQL server 2008 and importing data from excel,by using Imoprt and Export Data

there are two tables INVOICES

Hide Copy Code
COLUMN_NAME	DATA_TYPE Invoice_Id	varchar ItemName	varchar Quantity	bigint Amount	money Date_Time	datetime

and second table is RECEIPT

Hide Copy Code
COLUMN_NAME	DATA_TYPE Receipt_Id	varchar Invoice_Ref	varchar Amount	money Date_Time	datetime

and in INVOICES table Invoice_Id has primary key and in RECEIPT table Invoice_Ref has foreign key references from INVOICE table.
 
 

now suppose INVOICE001 have to pay 20000 in INVOICES table but he pay first receipt 10000 and then second receipt 10000 in RECEIPT table.

how we can check amount 20000 = 10000+10000 by SQL.
Means what I need to use, during creating RECEIPT table can we put any constraint for that?
 
how we can ensure that amount of INVOICES and Amount of RECEIPT table amount of(Receipt1 + Receipt2) is equal or may be less than but not greater than because he can pay one more receipt.please give me solution,i will be obliged you 
please help me.

Answers (2)