Get indentity field
Posted on 2009-04-06
i have table like this
ID // GUID, PK
Number //****this is an identity field
I have a stored proc that does this:
declare @code as varchar(5)
Select @code = code from AnotherTable where ...
insert into Table1 (Id,Number,NumberDisplay
select ID, Number, @code + cast([Number] as varchar(50))
This gives me an error :
Violation of PRIMARY KEY constraint 'PK_ORdNumberr'. Cannot insert duplicate key in object 'dbo.Table1'.
How can I concat that Number with the Code and insert at once??
If I cant insert at once, how can I get that Number and then maybe do an update right after the insert...
Any other ways of doing this? Issue is that [Number] has to be Identity..generated automatically... dont want
to manually generate that number..