Link to home
Start Free TrialLog in
Avatar of johnson1
johnson1

asked on

insert get identity - does not return correct number

Hello,
I have a table with identity column (Id).  I.e.   MyTable(Id int, MyNum int, MyText varchar(50), CreatedBy int)
I insert into it like this   MyTable(MyNum, MyText)values(3,'Mm')
Then I want to get the identity of the newest column.  I do it like this:
SELECT @@Identity.
The newest number in the identity column is 20993, but I get returned 1005.
I do not understand why this is. Can somebody please help.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
DECLARE @identity TABLE (
    id int
    )

INSERT INTO MyTable(MyNum, MyText) OUTPUT INSERTED.$IDENTITY INTO @identity values(3,'Mm')
Avatar of johnson1
johnson1

ASKER

Thank you very much. There was a trigger.