sql - How to write trigger which copies value of a column of a table to another column of another table? -


i have table tblbilling , tbltotalfee. 1 of column in tblbilling named remainingamount , in tbltotalfee have column named due previous month. want whenenver insert value in remaining amount want value automatically inserted due previous month. trying write trigger.but can't right?? can me??

i tried:

alter trigger [dbo].[trg_billing_totalfee] on [dbo].[tblbilling]  after insert  insert tbltotalfee(duefrompreviousmonth)  select remainingamount inserted 

give example:

 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       insert tbltotalfee (duefrompreviousmongh)     select remainingamount inserted go  insert tblbilling  select 25 union select 27 union select 33 go select * tblbilling select * tbltotalfee go  

final output result:

 id     |  remainingamount ------------------------- 1000   |    25 1001   |    27 1002   |    33 
 id     |  duefrompreviousmongh ------------------------- 1000   |    25 1001   |    27 1002   |    33 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -