根据存储过程更新三个表ABC,DEF,EFG:
CREATE PROCEDURE Abc_Update
@W_AbcCode varchar(1),
@AbcWorthRate integer,
@AbcKindRate integer
AS
update Abc set
AbcKindRate=@AbcKindRate,
AbcWorthRate=@AbcWorthRate
where AbcCode=@W_AbcCode
update DEF set
DEFKindRate=@AbcKindRate,
DEFWorthRate=@ABCWorthRate
where DEFCode=@W_AbcCode
update EFG set
EFGKindRate=@AbcKindRate,
EFGWorthRate=@AbcWorthRate
where EFGCode=@W_AbcCode
--通过主键ABCCODE,DEFCODE,EFGCODE关联三个表并同时显示三个表的数据:
SELECT * FROM ABC,DEF,EFG WHERE ABCCODE=DEFCODE AND DEFCODE=EFGCODE
GO
--使用举例:将ABC,DEF,EFG三个表CODE字段为A001的记录另外两个字段改为2和3.然后在界面中显示关联后的三个表的数据。
EXEC Abc_Update 'A001',2,3
--这是我做的财务系统里的一个例子
create procedure balanceUpdate
(
@month datetime,--这个时间是要计算的月份如4月
@site int ,
@cashnew money output,--分别是计算的结果
@chequenew money output,
@outernew money output
)
as
declare @cashold money--分别是计算的月份的前月3月余额表数据
declare @chequeold money
declare @outerold money
declare @cashthis money--日记统计的本月发生4月的数据
declare @chequethis money
declare @outerthis money
--先查余额表输入日期的前一个月的数据
select @cashold=[bal_cash],@chequeold=[bal_cheque],@outerold=[bal_outer]
from [finance_balance] where datediff(mm,@month,[bal_month])=-1 and [finance_balance].bal_site=@site;
print @cashold
--再查输入日期当月的所有发生累计(如果添入日期为2008-4-3 ,那么4-3以后的数据也被统计进来,就是说统计只看月份)
select @cashthis=sum(fin_item_sum) from [finance_daily_accounting]
where [fin_class]=1 and [finance_daily_accounting].fin_site=@site and datediff(mm,@month,fin_item_date)=0 ;
select @chequethis=sum(fin_item_sum) from [finance_daily_accounting]
where [fin_class]=2 and [finance_daily_accounting].fin_site=@site and datediff(mm,@month,fin_item_date)=0 ;
select @outerthis=sum(fin_item_sum) from [finance_daily_accounting]
where [fin_class]=3 and [finance_daily_accounting].fin_site=@site and datediff(mm,@month,fin_item_date)=0 ;
--@cashol,@chequeold,@outerold如果为null 那么结果为null 就是说输入日期的前月必须有余额数据 查询才有结果
select @cashnew=@cashold+isnull(@cashthis,0)
select @chequenew=@chequeold+isnull(@chequethis,0)
select @outernew=@outerold+isnull(@outerthis,0)
go
--测试
declare @cash money
declare @cheque money
declare @outer money
exec balanceUpdate '2008-4-1',1,@cash output,@cheque output,@outer output
select @cash as 现金,@cheque as 帐面,@outer as 帐外
selcet
from (多加几个表名字应该可以了)
update