0

テーブルtblBillingtblTotalFeeがあります。tblBillingの私の列の 1 つはRemainingAmountという名前で、tblTotalFee にはDue From Previous Monthという名前の別の列があります。今私が欲しいのは、Remaining Amountに値を挿入するたびに、その値をDue From Previous Monthに自動的に挿入することです。トリガーを書き込もうとしていますが、うまくいきませんか?? 誰でも私を助けることができますか??

私は試した:

ALTER trigger [dbo].[trg_Billing_TotalFee] on [dbo].[tblBilling] 
after insert as 
insert into tblTotalFee(DueFromPreviousMonth) 
select RemainingAmount from inserted
4

1 に答える 1

1

例を挙げてください:


create table tblBilling (ID int identity(1000,1) primary key,
                         RemainingAmount int 
                         )
go
create table tblTotalFee (ID int identity(1000, 1) primary key,
                          DueFromPreviousMongh int)
go 
create trigger tr_tblBillingSync on tblBilling 
after insert 
as 
    insert into tblTotalFee (DueFromPreviousMongh)
    select RemainingAmount from inserted
go 
insert into tblBilling 
select 25
union all select 27
union all select 33
go
select * from tblBilling
select * from tblTotalFee
go 

最終出力結果:


ID     |  RemainingAmount
-------------------------
1000   |    25
1001   |    27
1002   |    33

ID     |  DueFromPreviousMongh
-------------------------
1000   |    25
1001   |    27
1002   |    33
于 2013-04-05T08:38:12.983 に答える