Table Update

  • Hi! I need an update table syntax to Update the table with new records or update the existing records based on the Staffno, together with the period indicator

  • do u mean this? update table_name set col1 = valu1, col2 = value2 where staffno = staff_value and period = period_value

  • Could you give us a little more info? The table structure, some sample rows from that table and an example of what you want the result to look like?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • OK.

    I have a table IRchair which has columns staffno and clusterid. I am going to add to this table a clumn named period. So I need to bring into this table data for different periods(eg. jan, feb, march ....) without duplicating data.

    If a certain staffno exist in that table then I don't want to bring it in again

  • thatok (9/1/2008)


    OK.

    I have a table IRchair which has columns staffno and clusterid. I am going to add to this table a clumn named period. So I need to bring into this table data for different periods(eg. jan, feb, march ....) without duplicating data.

    If a certain staffno exist in that table then I don't want to bring it in again

    Can you please give us the table's structure (as a create table statement is easiest), some sample data and what you want it to look like after the update?

    Where are you data on the different periods from?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thatok (9/1/2008)


    OK.

    I have a table IRchair which has columns staffno and clusterid. I am going to add to this table a clumn named period. So I need to bring into this table data for different periods(eg. jan, feb, march ....) without duplicating data.

    If a certain staffno exist in that table then I don't want to bring it in again

    It's called an UPSERT or MERGE... without more data, my only suggestion would be to Google those two words.

    For better quicker answers, you may want to take the time to read the article at the link in my signature below.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks. That's exactly what I was looking for. Thanks everyone for your input

  • Thanks for the feedback...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 8 posts - 1 through 7 (of 7 total)

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