Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
SQL Server Newbies
»
Insert into...select from with an identity...
Insert into...select from with an identity column
Rate Topic
Display Mode
Topic Options
Author
Message
mcieslinski
mcieslinski
Posted Wednesday, April 30, 2008 1:01 PM
Grasshopper
Group: General Forum Members
Last Login: Thursday, March 25, 2010 1:05 PM
Points: 12,
Visits: 37
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
Post #493207
Jason Selburg
Jason Selburg
Posted Wednesday, April 30, 2008 1:05 PM
SSCrazy
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 7:55 AM
Points: 2,582,
Visits: 3,552
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
Post #493213
mcieslinski
mcieslinski
Posted Wednesday, April 30, 2008 1:17 PM
Grasshopper
Group: General Forum Members
Last Login: Thursday, March 25, 2010 1:05 PM
Points: 12,
Visits: 37
Wow, that was too easy.
Thanks so much. Tested that and it worked perfectly.
Post #493227
Jason Selburg
Jason Selburg
Posted Wednesday, April 30, 2008 1:20 PM
SSCrazy
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 7:55 AM
Points: 2,582,
Visits: 3,552
Yes, we all know too well that sometimes the hardest problem we work on is right in front of our face.
______________________________________________________________________
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
Post #493229
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.