Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2012
    Posts
    119

    Unanswered: trigger using merge and CTE

    Hi all,
    I have a trigger (see below) written for SQL Server, using a CTE and a merge statement.
    Would it be possible to write the same for DB2?
    I'm having difficulties in writing it could you please help?

    Thanks a lot

    CREATE TRIGGER update_items on RESULTS
    FOR INSERT
    AS
    with props
    as
    (
    select Id, ItemID, Result
    from RESULTS
    where
    Result <> '' and
    Id in (2,4,5)
    ) merge into COMPUTERS using props
    on props.Id = COMPUTERS.ComputerID
    when matched then
    update set IsReady = case when props.Id = 2 and LTRIM(RTRIM(props.Result)) = 'Yes' then 1 else IsReady end,
    OriginID = case when props.Id = 4 then props.Id else OriginID end;

  2. #2
    Join Date
    Jan 2003
    Posts
    4,286
    Provided Answers: 5
    For those of us who do not understand SQL Server, please explain the trigger.

    Andy

  3. #3
    Join Date
    Jan 2003
    Posts
    4,286
    Provided Answers: 5
    Can you show us what you tried and the result?

    Andy

Posting Permissions

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