Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi

i have 2 table...

first...
tbl_Purchase
SQL
Purchase_id	bigint	
Location_Id	bigint	
PU_Ref	nvarchar(50)	
InvoiceDate	datetime	
Original_Amt	decimal(18, 2)	
Supplier_ID	bigint	
Status	int

and second
tbl_pur_Child
SQL
s_N	bigint	
Purchase_ID	bigint	
Paid_amt	decimal(18, 2)	
Location_Id	bigint	
InvoiceDate	datetime	


i want when i pass supplier id
in store procedure

so
it return
PU_Ref , Original_Amt , ( Original_Amt -sum(Paid_amt ) of particule supplier id...

1 supplier may can have more then 1 invoices....

i write this store procedure...
SQL
ALTER procedure [dbo].[SP_Chk_Purchase_Bal_By_SupID]
 @supid int
as begin
 
select PU_Ref ,Original_Amt, (Original_Amt-
(select sum(rf.Paid_amt) from tbl_pur_Child as rf join
 
tbl_Purchase as pu  on
rf.Purchase_ID=pu.Purchase_id ))
from tbl_Purchase where Supplier_ID=@supid
 
end

but it not giving right result...............
Posted
Updated 24-Sep-11 2:33am
v2
Comments
#realJSOP 23-Sep-11 8:21am    
Not a question
dilip.aim11 23-Sep-11 8:22am    
means?

1 solution

you can try something like:

SQL
ALTER procedure [dbo].[SP_Chk_Purchase_Bal_By_SupID]
 @supid int
as begin

 declare @amt_paid float


select @amt_paid = sum(rf.Paid_amt) from tbl_pur_Child as rf join
tbl_Purchase as pu  on
rf.Purchase_ID=pu.Purchase_id where Supplier_ID=@supid

select
    PU_Ref ,
    Original_Amt,
    (Original_Amt- @amt_paid)
from tbl_Purchase where Supplier_ID=@supid

end
 
Share this answer
 
Comments
dilip.aim11 23-Sep-11 8:25am    
its also giving same result....

it addall the pay amount...
even of diffrent purchase id....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900