How to run a trigger if a field is not null?

  • Hi,

    I must to shot a trigger if a field is not null, but I have no idea on how to do that?

    Can someone give me a clue?

    Best Regards,

  • Not sure what you mean.

    Triggers fire when data is inserted, update, and/or deleted. Are you looking for a trigger that fires on an insert if a certain row is populated? Or on an update? Or something else?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Hi,

    Thanks for the reply.

    I need to send and e-mail if a field is not null. If on insert or update the field is not null the trigger should fire.

    How can I do this?

    Sorry for my bad english.

    Best Regards,

  • what have you tried so far?

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Take a look at "create trigger" in Books Online or on MSDN. It has the syntax for creating triggers. You can use the "inserted" table to select from, and that will tell you if the field is null or not. Then you'll want to have sp_send_dbmail enabled (look that up in BOL/MSDN), and you can use that in the trigger to send the e-mail.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Sounds like you first need a course in triggers. Here's an introductory article on triggers[/url] that may help.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply