Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 passing @@Identity to a variable?

Author  Topic 

vicpal25
Starting Member

21 Posts

Posted - 2008-07-23 : 14:22:04
Im bombing on this line:

SET @CfIdentity=SELECT @@IDENTITY

How can I pass the identity to a variable?

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-23 : 14:26:09
SELECT @CfIdentity = @@IDENTITY
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-23 : 14:54:36
Or even better (as @@IDENTITY should be avoided):

SET @CfIdentity = SCOPE_IDENTITY()

I use SELECT only when dealing with multiple variables.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-24 : 03:01:17
quote:
Originally posted by vicpal25

Im bombing on this line:

SET @CfIdentity=SELECT @@IDENTITY

How can I pass the identity to a variable?



That should be

SET @CfIdentity=(SELECT @@IDENTITY)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-24 : 04:27:10
Refer this for understanding difference b/w @@IDENTITY & SCOPE_IDENTITY

http://blog.falafel.com/2008/04/23/TSQLTheDifferenceBetweenIdentityScopeidentityAndIdentcurrent.aspx
Go to Top of Page
   

- Advertisement -