Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2007
    Posts
    33

    Question Unanswered: Urgent Help Needed - Creating A Trigger?

    I want a stored procedure to run everytime the batch Status field is set to 'Released'


    <Code>
    CREATE TRIGGER [CSITSS].[tdecker].[FB401BV_TRIGGER] ON [CSITSS].[dbo].[Fbbatch] FOR UPDATE [Status]

    AS


    DECLARE @RC int
    DECLARE @Batch int

    SET @Batch = (??? BATCH NUMBER THAT WAS SET TO RELEASE ???)

    EXEC @RC = [CSITSS].[tdecker].[GLP_FB401BV_BATCH] @Batch

    </Code>

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Select the batch number form the inserted virtual table.

  3. #3
    Join Date
    Feb 2007
    Posts
    33

    Question How

    How do I select from the Updated Table?

  4. #4
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    There is no UPDATED table. Read MCrowley's post very, very carefully.

    -- This is all just a Figment of my Imagination --

  5. #5
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    You do not. There is no updated table. Check the article titled "Using the inserted and deleted Tables" in BOL.

  6. #6
    Join Date
    Feb 2007
    Posts
    33

    Question Does This Look Correct?

    <Code>
    CREATE TRIGGER [CSITSS].[tdecker].[FB401BV_TRIGGER] ON [CSITSS].[dbo].[Fbbatch] FOR UPDATE [Status]

    AS

    DECLARE @Status Char (12)
    DECLARE @RC int
    DECLARE @Batch int
    SET @Status = (Select [Status] FROM INSERTED)

    IF @Status = 'Released'
    BEGIN
    SET @Batch = (Select [Batch] FROM INSERTED)

    EXEC @RC = [CSITSS].[tdecker].[GLP_FB401BV_BATCH] @Batch

    END

    </Code>

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What happens if more than one record is updated?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Feb 2007
    Posts
    33

    Question This one works!

    This script works.

    There is a button in the program that sets a batch to release. There is only one record in the Fbbatch table for each batch.

    If two users clicked the Release Button at the same time wouldn't they be assigned seperate threads and both would trigger this event? Not at the same time?


    <Code>
    CREATE TRIGGER [FB401BV_TRIGGER] ON [CSITSS].[dbo].[Fbbatch] AFTER UPDATE

    AS
    IF UPDATE ( [Status] )
    DECLARE @Status Char (12)
    DECLARE @RC int
    DECLARE @Batch int
    SET @Status = (Select [Status] FROM INSERTED)

    IF @Status = 'Released'
    BEGIN
    SET @Batch = (Select [Batch] FROM INSERTED)

    EXEC @RC = [CSITSS].[tdecker].[GLP_FB401BV_BATCH] @Batch

    END
    </code>

  9. #9
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    your trigger will not work if an update statement is run against the table that affects more than one record. you may say that is not how the application works but that kind of thing can change. every trigger should be written to handle mass updates.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  10. #10
    Join Date
    Feb 2007
    Posts
    33

    Question Trigger Works BUT PREVENTED UPDATE

    The trigger fires but it prevented somehow the status from being changed to 'Released'. The program acts as if it has changed but it actually hasn't. It won't allow you to print orders that haven't been released. So I removed my trigger and the program works as designed again.

    I'm now sure why this happened?

    How would i go about handleing more than one updated record in a trigger? Using a cursor?

Posting Permissions

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