任何人都可以通过显示用于从三个表计算总会费的创建过程语句来帮助我吗?这是表格及其数据..
表格1
accountno shipername shiperaddress Executivename
001 john 123, London Paul
002 Robi 127, China Soma
表_2
Executivename shipername shiperaddress accountno currentamount anotheramount
paul john 123,london 001 10500 12000
soma robi 127,china 002 11000 6800
表3
accountno Date ReceivedAmount MoneyReceiptNo
001 1/1/2012 6500 G 256412
002 1/2/2012 5200 D 246521
在这里我要提一下,总会费将计算为
(currentamount + anotheramount) - receivedamount
我试图通过以下存储过程来做到这一点。
CREATE PROCEDURE [dbo].[rptexetotaldues] @Executivename varchar(20)
AS BEGIN
select
table_1.Executivename,
sum(table_2.currentamount + table_2.anotheramount
- table_3.receivedamount ) as TotalDues
from
table_1
full join
table_2 on table_1.accountno = table_2.accountno
join
table_3 on table_3.accountno = table_1.accountno
where
table_1.Executivename = @Executivename
group by
table_1.Executivename
end
但这不起作用。请有人帮助我。