sql - Trigger to Truncate then Insert rows -


everyday, rows inserted sql server table (t_past). these rows records past (ie august 1, 2013) records in future (ie january 1, 2014). want leave past dated records in table (t_past), future date records, to: 1) delete them original table 2) insert them new table has future dated records (t_future)

the thing is, future dated records can have changes in columns, instead of running update query well, prefer truncate t_future table, , reinsert records.

everything works in sense proper records insert t_past, proper records delete t_past , t_future table truncated. problem when insert multiple future dated records, last record shows in t_future table, not of them.

alter trigger [dbo].[trg_getfuture] on [dbo].[t_past] after insert  begin truncate table dbo.t_future end  begin insert dbo.t_future select * inserted date > getdate() end  begin delete dbo.t_past date > getdate() end 

thanks!!

this because truncating t_future table in trigger. every time trigger fired first truncate t_future table , insert new records table.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -