Results 1 to 3 of 3

Thread: Writing a Trigger - Help

  1. #1
    Join Date
    Jan 2007
    Posts
    2

    Writing a Trigger - Help

    Hi Guys,

    I am trying to create my first trigger.

    I have a table called qdDutyEvents with fields starttime, and OpDay =(Operational day (Monday, Tuesday, Wednesday etc)
    I need to check that when a new start time is entered into my table that it doesn’t already exists on the same operational day.
    In other words if OPDay = Monday then I can only have ONE starttime of 08:00

    I do not know is how write the trigger to monitor all the records in the table, actually how to start at the beginning of the table and run through the records and check if my Opday is Monday(for example) and starttime 08: 00 if it already exists it must send an error and NOT update the table

    Anybody that could help me PLEASE, Please, Please


    TopCat

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    On which rdbms?

  3. #3
    Join Date
    Jan 2007
    Posts
    2
    Hi rmiao

    Thanks for replying, but I figured it out
    I created a temp table and as I dump new records in, I compare the startdates and as soon as I have more than one I just delete them

    WHERE int2_OpDays & @ MyOpDays > 0

    IF EXISTS (SELECT * FROM #Tmp)
    BEGIN
    RAISERROR ('Duplicate Start timeinserted into qdDutyevents', 16,1)
    ROLLBACK TRANSACTION

    END
    the duplicates.

    So till I start sweating with th next problem......

    you'll here from me again

    Have a marvellous day

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •