Wednesday, March 28, 2012

How to assign the @@IDENTITY to a variable

Hi,

HOW can I assign the value of @.@.IDENTITY to the any variable in SQL SERVER .

Thanks,


DECLARE @.var int
INSERT INTO <table> VALUES <...> SELECT @.var= @.@.IDENTITY

On another note, I'd recommend using SCOPE_IDENTITY() instead of @.@.IDENTITY. check out books online for some info. ScopeIdentity is more accurate in returning the autonumber id.

No comments:

Post a Comment