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
 General SQL Server Forums
 New to SQL Server Programming
 indentity

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-20 : 08:17:36
Arkadiy writes "Why @@indentity returns NULL after inserting new row?"

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-02-20 : 08:36:59
post your code here

and its better to user scope_identity() function, see books online
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-20 : 09:10:05
Does your table have identity column?
Also that should be @@identity and not @@indentity

Madhivanan

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

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-02-20 : 09:12:56
Ensure you actually have an identity column in the table inserted, as well....


set nocount on
create table ##testidentity
(i int)

insert into ##testidentity (i) values (1)

select @@identity
select * from ##testidentity

create table ##testidentity2
(uid int identity (1,1),
i int)

insert into ##testidentity2 (i) values (1)

select @@identity
select * from ##testidentity2
--RESULT
----------------------------------------
NULL

i
-----------
1


----------------------------------------
1

uid i
----------- -----------
1 1



*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-02-20 : 09:13:47
lol - nice x-post eh Madhivanan?



*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-21 : 00:32:56
I think I was faster than you

Madhivanan

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

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2006-02-21 : 03:27:05
yeah... you were faster, but I had an example :-)

*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page
   

- Advertisement -