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  
 
programming4us programming4us