Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Insert into...select from with an identity column Expand / Collapse
Author
Message
Posted Wednesday, April 30, 2008 1:01 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 29, 2013 9:14 AM
Points: 12, 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
Post #493207
Posted Wednesday, April 30, 2008 1:05 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:58 AM
Points: 2,705, Visits: 3,768
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
Posted Wednesday, April 30, 2008 1:17 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 29, 2013 9:14 AM
Points: 12, Visits: 38
Wow, that was too easy.

Thanks so much. Tested that and it worked perfectly.
Post #493227
Posted Wednesday, April 30, 2008 1:20 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:58 AM
Points: 2,705, Visits: 3,768
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 »

Add to briefcase

Permissions Expand / Collapse