troubleshooting Question

Help in fine tune my SQL Server trigger.

Avatar of Cobra967
Cobra967Flag for United States of America asked on
Microsoft SQL Server
17 Comments1 Solution103 ViewsLast Modified:
Hello I need help in fine tune my SQL Server trigger. I need this trigger to execute *ONLY* when the *PhoneNumber* is updated from nothing (NULL) to something and from something to something else (If updating from something to nothing (NULL) then it will not execute.  In shot, the trigger will copy most of the data from table [DATA] record into Table [FOLLOWUP] if the phone number has been added or changed in table [DATA] Thank you.

USE [prd_customers]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[SetFollowUp]
 ON [dbo].[DATA]
 AFTER UPDATE
 AS
 SET NOCOUNT ON;
 INSERT INTO dbo.FOLLOWUP ( 
     RecordIdFK, 
	 FullName, 
	 Address, 
	 City, 
	 State, 
	 Zip, 
	 PhoneNumber, 
	 eMail, 
	 Notes)
 SELECT
	 i.RecordId,
	 i.FullName, 
	 i.Address, 
	 i.City, 
	 i.State, 
	 i.Zip, 
	 i.PhoneNumber, 
	 i.eMail, 
	 i.Notes 
 FROM inserted i
 WHERE PhoneNumber is not null
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros