Getting latest record from trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mccax
    New Member
    • Jul 2007
    • 1

    #1

    Getting latest record from trigger

    Hello,

    I have the following table (UNIQUOTE) with data in it:

    Opportunity_Id Rx_Combo Plan_Type
    B6FG3JX5G $27/$48/$28 HMO
    B6FG3JX5G $88/$33/$99 HMO
    B6FG3JX5G $16/$17/$18 HMO

    There is a trigger on the table that updates another table (opport) on insert. The problem is that if I have an update to make to Rx_Combo it always grabs the first record no matter what. Any ideas on how to get it to update with the current/latest record data? I've looked into SCOPE_IDENTITY( ) but it can't get it to work. Any ideas? Here's the trigger:

    CREATE TRIGGER [update_opportun ity_hmo] ON [dbo].[UNIQUOTE]
    FOR INSERT
    AS
    update opport set
    opport.HMO_COMP _RX_COPAY=UNIQU OTE.rx_combo,
    from opport, UNIQUOTE
    where UNIQUOTE.opport unity_id=opport .id
    and uniquote.plan_t ype='HMO'
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by mccax
    Hello,

    I have the following table (UNIQUOTE) with data in it:

    Opportunity_Id Rx_Combo Plan_Type
    B6FG3JX5G $27/$48/$28 HMO
    B6FG3JX5G $88/$33/$99 HMO
    B6FG3JX5G $16/$17/$18 HMO

    There is a trigger on the table that updates another table (opport) on insert. The problem is that if I have an update to make to Rx_Combo it always grabs the first record no matter what. Any ideas on how to get it to update with the current/latest record data? I've looked into SCOPE_IDENTITY( ) but it can't get it to work. Any ideas? Here's the trigger:

    CREATE TRIGGER [update_opportun ity_hmo] ON [dbo].[UNIQUOTE]
    FOR INSERT
    AS
    update opport set
    opport.HMO_COMP _RX_COPAY=UNIQU OTE.rx_combo,
    from opport, UNIQUOTE
    where UNIQUOTE.opport unity_id=opport .id
    and uniquote.plan_t ype='HMO'

    try getting the value from inserted/deleted tables

    Comment

    Working...