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 2000 Forums
 Transact-SQL (2000)
 Identity Issue

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-08-22 : 15:19:35
I inserted into table tbl_emp_details and the number of records affected was 0.Basically nothing got inserted But when
printed @emp_id I was able to get some value..Why is it giving me value.Below shown is the satement I am using after the insert

SELECT @error_int=@@error,@no_of_records_processed=@@ROWCOUNT,@emp_id =@@IDENTITY

PRINT @emp_id

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-22 : 15:48:18
That's why you ned to check @@ROWCOUNT or whatever you are expecting prior to doing anything with @emp_id.

Tara Kizer
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2006-08-22 : 15:51:33
But I need to know the error number, no of records affected and the identity value for the insert.Please help me in how i can code differently
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-22 : 15:52:19
You can still use that statement. Just don't do anything with @emp_id's value afterward until you know for sure to continue on.

Tara Kizer
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-08-23 : 09:07:44
From BOL:
@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.



For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -