Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing previously inserted primary key

Status
Not open for further replies.

chrissparkle

Programmer
Mar 27, 2006
50
NZ
I have a table where I need to insert the primary key field after it has been inserted into the same row (but another column).

I could do an Update after the Insert obviously using SCOPE_IDENTITY or IDENTITY into the other column but I'd like to do it within the same insert if its at all possible.

Is there a way to do this?
 
hmm,

this is a wild guess, but why dont you use the Scope_Identity() function in your insert statement itself for that column???

Known is handfull, Unknown is worldfull
 
Another wild guess, but if you need to have a column have the same value as another column, you could just create a computed column and set it equal to you key field:
CREATE TABLE [dbo].[tbl_Test](
[MyKey] [int] NOT NULL,
[Calculated_Column] AS ([MyKey])
)

Thanks,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top