Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    202

    Unanswered: copy data from 1 table to other in stored procedure in sql server

    Hi there,

    Can u please tell me how to copy data from table A(database A) to table B(databaseB) which table A contain 10 fields but table B consist of 11 fields. I have to insert current date and time into another field in Table B (which has extra field compare to tableA) automatically every hour or so.
    Please help.
    Thanx

  2. #2
    Join Date
    Mar 2004
    Posts
    202

    Re: copy data from 1 table to other in stored procedure in sql server

    Originally posted by michaelfg81
    Hi there,

    Can u please tell me how to copy data from table A(database A) to table B(databaseB) which table A contain 10 fields but table B consist of 11 fields. I have to insert current date and time into another field in Table B (which has extra field compare to tableA) automatically every hour or so.
    Please help.
    Thanx
    if my code in sql query analyszer like below

    insert into esipquery.dbo.tsip_wip
    select assy_lot_no, location_id, traveler_type, ase_lot_no, device_type, process_id,
    process_rev, sequence, in_qty, out_qty, status, check_in_date, check_in_time,
    check_out_date, check_out_time, package_grp, cust_id, ex_lot, getdate() as create_time
    from esipdata.dbo.vSIP_LOT_TRACK_WIP

    and i get error sound like this:

    Server: Msg 2627, Level 14, State 1, Line 1
    Violation of PRIMARY KEY constraint 'PK_tSIP_WIP'. Cannot insert duplicate key in object 'tSIP_WIP'.
    The statement has been terminated.

    after i made a check on it, i found out that one of the primary key in table esipquery.dbo.tsip_wip
    is not a primary key in table esipdata.dbo.vSIP_LOT_TRACK_WIP

    How can i fix it?
    Can anyone pls help me
    Thanx

  3. #3
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    Post the table structure, including the primary keys and indexes. You have a primary key defined on the table you are inserting into. You keep trying to insert a value into that table, which is alread there. This won't work.
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

Posting Permissions

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