Insert/Update the evex_no in TX_EVENT_EXTRACT

Former Member
Former Member $organization

Hi all,

 

Last week I inserted 208 rows into TX_EVENT_EXTRACT and did the following to get around the evex_no (code below). However, being the SQL newbie I am…..didn’t realize that this would break the evex_no for any further invitations added in the normal way. As a temporary solution, I have updated my 208 inserts so that their evex_no are +1000 so duplicates won’t come up for a while.

 

Does anyone know how/where I can insert my evex_no’s so they are recognized and recorded correctly in the system?

 

Also, how do others get around doing Insert Select statements with a non-identity column as a PK? I searched and search online but couldn’t find anything. I hope I have made sense….

 

Thanks as always,

 

Tash

 

Declare

            @maxid int

 

Set   @maxid = (Select MAX(evex_no)+1 from TX_EVENT_EXTRACT)

      While exists (Select * from #invitations)

 

Begin

      If @maxid in (select evex_no from TX_EVENT_EXTRACT) continue;

 

Insert into TX_EVENT_EXTRACT

Select top 1

                  @maxid,

                  a.campaign_no,

                  a.customer_no,

                  a.source_no,

                  a.inv_status,

                  a.reserved_ind,

                  a.recd_amt,

                  a.num_attendees,

                  a.notes,

                  a.mir_lock

      from  #invitations a

 

Set @maxid = @maxid+1

 

delete from #invitations where customer_no in (Select MIN(customer_no)from #invitations)

 

End

Parents
  • You can use AP_GET_NEXTID_function @type='EV' for that table specifically. Probably right now what you really need to do is get the max evex_no you've currently got in tx_event_extract and update t_next_id so it's +1 that number where type='EV'. I think right now that table actually stores the current max, not in fact the "next" id, but I think in v11 it switches.

  • Former Member
    Former Member $organization in reply to A. Freeman

    And just adding to Amanda's note - what people mostly do when they want to add a chunk of their own rows into one of those next_id-controlled  tables is

    • either
    1. add them one at a time, and call the  AP_GET_NEXTID_function for that Type (EV in this case) to get a new id for each one,
    •  or
    1. count how many rows they're going to insert, 
    2. add that number (plus a few for safety) to the T_next_id value for the Type - to effectively reserve a block of numbers for them to use below the new NEXT_ID;
    3. allocate numbers from  the reserved block to their import set records 
    4. INSERT them into the table  

    Ken

  • Former Member
    Former Member $organization in reply to Former Member

    Thanks so much Amanda and Ken. Table is back in working order!

Reply Children
No Data