Update or Insert SQL Codding help

  • Dear expert

    I am using import/export wizard to upload excel in sql table

    I have primary key in my table

    and all primary key value has been change every day

    i.e. I have customer wise sales data and having 10 customer and sales value (two column in table), every day sales value increase/change, and new customer also adding every day

    now every day I drop this table and update table as fresh file

    but while uploading excel file can I use sql code which do as follow

    1) if primary key exist in table update sales value (as per excel file) source file

    2) if primary key does not exist then update in table as new row.

  • atul.jadhav (1/30/2015)


    Dear expert

    I am using import/export wizard to upload excel in sql table

    I have primary key in my table

    and all primary key value has been change every day

    i.e. I have customer wise sales data and having 10 customer and sales value (two column in table), every day sales value increase/change, and new customer also adding every day

    now every day I drop this table and update table as fresh file

    but while uploading excel file can I use sql code which do as follow

    1) if primary key exist in table update sales value (as per excel file) source file

    2) if primary key does not exist then update in table as new row.

    now every day I drop this table

    if primary key exist in table

    Can you clarify and elaborate please? Currently this makes no sense.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • atul.jadhav (1/30/2015)


    Dear expert

    I am using import/export wizard to upload excel in sql table

    I have primary key in my table

    and all primary key value has been change every day

    i.e. I have customer wise sales data and having 10 customer and sales value (two column in table), every day sales value increase/change, and new customer also adding every day

    now every day I drop this table and update table as fresh file

    but while uploading excel file can I use sql code which do as follow

    1) if primary key exist in table update sales value (as per excel file) source file

    2) if primary key does not exist then update in table as new row.

    Lots of words here, but no questions. What do you want help with?


  • Dear both, in simple I want to append SQL table thru import/export wizard (from excel file) and that table having only tow column,

    1) Customer Account No (Primary key/unique no.)

    2) Sales Amount

    now what I want,

    1) if primary key exist in table update sales value (as per excel file) source file

    2) if primary key does not exist then update in table as new row.

    I hope I clear now,

    Please go thru attachment file where I have mentioned with existing table, excel to be upload and expected result in SQL table

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply