Microsoft
Software
Hardware
Network
Question : Creating an Update trigger for a specific column
I have a table called tblEvents and I'm trying to create an update trigger for a column called ConnectedEventID
When this columnis populated with a value, I want it to do a lookup in tblEvents and put the EventStartTime into the column ConnectedEventStartTime for the record being updated.
I'm at a loss to write the t-sql.
I am using the syntax
IF COLUMN(ConnectedEventID)
--Check to see if the ConnectedEventID IS NOT NULL
--Update the ConnectedEventStartTime with the EventStartTime value from the record matching the value of the ConnectedEventID column
but am not sure how to tell if the updated column has a value or is being set to null.
Could someone please point me in the write direction?
Thanks,
Mike
Answer : Creating an Update trigger for a specific column
Try using this as a start:
declare @ConnectedEventID integer
-- check if column is being updated
if update(ConnectedEventID)
begin
-- get new value
select @ConnectedEventID = ConnectedEventID
from inserted
-- check if new value is not null
if not (@ConnectedEventID is null) then
begin
-- code here for when ConnectedEventID has a value you care about
end
end
Random Solutions
After Acronis restore of Windows Server 2003 Domain Controller to new box, Exchange server cannot see Domain Controller
Backup and Restore Permissions on a Server
How to parse the output of a command in a Bash script
Does AOL log im conversations?
3.0 vs 4.0
Windows Server 2003 FSMO role
Bcp Failing
Server shutdown itself
Sendmail problems - dsn=4.0.0, stat=Deferred
restored old Exchange mailbox from tape, message body missing, but sender and subject show, BackupExec 12 on SBS 2003