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
  • My own favourite way of doing this these days (and I'm doing a LOT of data import!) without using a cursor is to use the ROW_NUMBER() function:

     

    declare @@pt_no int

    set @@pt_no = (select MAX(id) + 1 from LT_IMPORT_PRICETYPE_MATCHUP)

     

    insert into TR_IMPORT_PRICETYPE_MATCHUP

    (id, price_type, matchup_text, inactive, created_by, create_dt, create_loc)

     

    select 

    ROW_NUMBER() over (order by pt1.enta_discount_code) + @@pt_no id,

    pt2.Tess_price_type_ID price_type,

    substring(pt1.Enta_Discount_code,1,30) matchup_text, 

    'N' inactive,

    'mkeen' created_by,

    GETDATE() create_dt,

    'STC325' create_loc

    from LT_ENTA_PRICETYPE_MATCHUP pt1

    join LT_ENTA_PRICETYPE_MATCHUP pt2 on pt1.Tessitura_equivalent=pt2.Tess_Price_type_description

  • But DON'T forget to update the T_NEXT_ID table where appropriate!

     

    update T_NEXT_ID

    set next_id = (select evex_no from TX_EVENT_EXTRACT) + 10

    where parent_table = 'TX_EVENT_EXTRACT'

     

Reply Children