Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Insert into...select from with an identity column


Insert into...select from with an identity column

Author
Message
mcieslinski
mcieslinski
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 38
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
Select NEWID(),
[company name],
[subscriber ID],
[process date],
etc.
from DEV..RBT_test

Thanks
Jason Selburg
Jason Selburg
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2983 Visits: 4106
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 you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
mcieslinski
mcieslinski
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 38
Wow, that was too easy.

Thanks so much. Tested that and it worked perfectly.
Jason Selburg
Jason Selburg
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2983 Visits: 4106
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 you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search