Trigger on Age of 18

  • Hi,

         I am in a fast-food industry. My HR department requests to have a trigger on the day there's someone who is turning to the age of 18.  We have a BOD column as datatype of smalldatetime. 

    I don't have an experience on creating trigger.  Does someone can help me out?  thanks.

  • Trigger happen when you change a record (INSERTS or UPDATES) so if I Update a table I can take some kind of action.  If you are running SQL Server 2000 go to Query Analyzer and press Ctl+N and you will get template code for all kinds of stuff, including different triggers.   Within the trigger I can do stuff based on the data I am inserting or updating.  For example if I update a certain column I can take some action as opposed to no action if some other column is updated.  If today is someone's birthday and noone updates their row in the table the trigger is of no use.

    What you can do is create a job that runs every morning that checks everyones birthday and do what ever you wanted to do (send them a birthday email or whatever)  Triggers won't help. 

    See http://www.databasejournal.com/features/mssql/article.php/1459151 for a sample UDF to get someone's age.

     

    Francis

  • Trigger happen when you change a record (INSERTS or UPDATES) so if I Update a table I can take some kind of action.  If you are running SQL Server 2000 go to Query Analyzer and press Ctl+N and you will get template code for all kinds of stuff, including different triggers.   Within the trigger I can do stuff based on the data I am inserting or updating.  For example if I update a certain column I can take some action as opposed to no action if some other column is updated.  If today is someone's birthday and noone updates their row in the table the trigger is of no use.

    What you can do is create a job that runs every morning that checks everyones birthday and do what ever you wanted to do (send them a birthday email or whatever)  Triggers won't help. 

    See http://www.databasejournal.com/features/mssql/article.php/1459151 for a sample UDF to get someone's age.

     

    Francis

  • I agree that a trigger won't work.

    The idea to schedule a job is good, but I wouldn't run this every morning.

    What happens when someone gets 18 on a saturday or sunday?

    I would create a procedure that gives you a resultset of who will become 18 within the next say 30 days from now. This way your HR department has enough time to react.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

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