Insert into...select from with an identity column

  • I have a table of healthcare claims data for which I would like to have a unique identifier for each row. I have acheived this in the past by creating a temporary table with an identity column and then inserting those rows into my final table. I use a variable to find the maximum value in the destination table. The data type in the final table, in this example, is bigint.

    I will receive claims data on a recurring basis from various clients and I am creating a procedure to add the new claims to an existing table.

    I was wondering if I could directly insert the claims into the destination table which will have an identity column. I tried to use NEWID() and that did not work.

    Here is a sample of my insert statement:

    Insert Into DEV..REBATEPRIMARY

    SelectNEWID(),

    [company name],

    [subscriber ID],

    [process date],

    etc.

    from DEV..RBT_test

    Thanks

  • If the target table has an identity column defined, then don't include it in your insert statement and it will be automatically populated at the time of insert.

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Wow, that was too easy.

    Thanks so much. Tested that and it worked perfectly.

  • Yes, we all know too well that sometimes the hardest problem we work on is right in front of our face. :hehe:

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg

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

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