DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to fill in missing data with a trigger?

The following Microsoft SQL Server T-SQL code sample demonstrates trigger creation. Starting with SQL Servr 2005, the OUTPUT clause is available as well for similar task.

-- UPDATE, INSERT trigger - inserted / deleted special tables
-- Investment banking example - missing data fill in second table

CREATE TRIGGER trgFillInMissingCouponRate

ON [dbo].StateTaxFreeBond

FOR INSERT,UPDATE

AS

BEGIN

      UPDATE StateTaxFreeBondArchive

            SET CouponRate = isnull(i.CouponRate,m.CouponRate)

      FROM StateTaxFreeBondArchive m

            INNER JOIN inserted i

                  ON m.MBCID = i.MBCID

END

GO

 

-- Equivalent code

CREATE TRIGGER trgFillInMissingCouponRate

ON [dbo].StateTaxFreeBond

FOR INSERT,UPDATE

AS

BEGIN

      UPDATE m

            SET CouponRate = isnull(i.CouponRate,m.CouponRate)

      FROM StateTaxFreeBondArchive m

            INNER JOIN inserted i

                  ON m.MBCID = i.MBCID

END

GO

------------

 

Related articles:

 

CREATE TRIGGER

 

Exploring SQL Server Triggers

 

http://www.sqlusa.com/bestpractices2005/columnupdatetrigger/

 

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE