• Bhuvnesh

    What I meant is that you should use an ORDER BY when SELECTing, not when INSERTing. So instead of this:

    -- INSERT data into destination table

    insert into email_destination_bk

    select ut_stub,acct_id , evt_stub , evt_code

    from email_source_bk

    where acct_id = 2000122

    order by acct_id,evt_code

    -- SELECT data from destination table

    select ut_stub,acct_id , evt_stub , evt_code

    from email_destination_bk

    you'd do this:

    -- INSERT data into destination table

    insert into email_destination_bk

    select ut_stub,acct_id , evt_stub , evt_code

    from email_source_bk

    where acct_id = 2000122

    -- SELECT data from destination table

    select ut_stub,acct_id , evt_stub , evt_code

    from email_destination_bk

    order by acct_id,evt_code

    Bear in mind that if you want data stored in a table in a certain order then you need to create the appropriate clustered index on the table. Bear in mind also that even this doesn't absolutely guarantee that your SELECT statement will return the data from that table in that order, unless you include an ORDER BY clause.

    John