Hi.
i have written an stored procedure(Insert Statement) in sqlserver 2008r2 and i want it to return the last Idcode(this one in my table is Identity) in my table, so i have two problem :
1- what is the difference between these two codes:
Return @@Identity
and;
Set Idcode=@@Identity
2- which one of two above statement has to be called?
and where ? i mean inside
Begin End
or outside
Begin End
??
my query is :
CREATE PROCEDURE [dbo].[Insert_Person_SP](
@PersonelCode nvarchar(20),
@NonIranPersonId int,
@SodourCityId int,
@CityId int ,
@GenderId int,
@MilitaryStatusId int,
@MaritialStatusId int,
@IsEmployee bit,
@IsTeacher bit,
@LastName nvarchar(60),
@FirstName nvarchar(60),
@FatherName nvarchar(50),
@BirthDate_S date,
@SerialNumber nvarchar(50),
@NationalNumber nvarchar(10),
@PostalCode nvarchar(10),
@Phone nvarchar(25),
@Mobile nvarchar(20),
@HomeAddress nvarchar(300),
@Email nvarchar(50)
)
AS
begin
Insert into Persons(
PersonelCode,
NonIranPersonId,
SodourCityId,
CityId,
GenderId,
MilitaryStatusId,
MaritialStatusId,
IsEmployee,
IsTeacher,
LastName,
FirstName,
FatherName,
BirthDate_S,
SerialNumber,
NationalNumber,
PostalCode,
Phone,
Mobile,
HomeAddress,
Email
)
values(
@PersonelCode,
@NonIranPersonId,
@SodourCityId,
@CityId,
@GenderId,
@MilitaryStatusId,
@MaritialStatusId,
@IsEmployee,
@IsTeacher,
@LastName,
@FirstName,
@FatherName,
@BirthDate_S,
@SerialNumber,
@NationalNumber,
@PostalCode,
@Phone,
@Mobile,
@HomeAddress,
@Email
)
return @@Identity
end