sqlserver中存储过程中的插入语句出现问题? [英] problem with Insert statement in stored procedure in sqlserver?

查看:110
本文介绍了sqlserver中存储过程中的插入语句出现问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我在sqlserver 2008r2中写了一个存储过程(插入语句),我希望它返回表中的最后一个IDcode(我表中的这个ID是Identity),所以我有两个问题:

1-这两个代码有什么区别:

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-必须调用以上两个语句中的哪一个?
在哪里?我的意思是在



2- which one of two above statement has to be called?
and where ? i mean inside

Begin   End


或在

Begin   End

之外???

我的查询是:

??

my query is :

CREATE PROCEDURE [dbo].[Insert_Person_SP](
@PersonelCode nvarchar(20),
@NonIranPersonId int,
@SodourCityId int,
@CityId int ,
--@MazhabId int,
@GenderId int,
@MilitaryStatusId int,
@MaritialStatusId int,
@IsEmployee bit,
@IsTeacher bit, 
--@JobTitle nvarchar(50),
--@JobDescribtion nvarchar(500),
@LastName nvarchar(60),
@FirstName nvarchar(60),
@FatherName nvarchar(50),
--@NationalityId
@BirthDate_S date,
@SerialNumber nvarchar(50),
@NationalNumber nvarchar(10),
@PostalCode nvarchar(10),
@Phone nvarchar(25),
@Mobile nvarchar(20),
@HomeAddress nvarchar(300),
@Email nvarchar(50)
--@Photo
--@PhotoPath
)
AS
begin
Insert into Persons(
PersonelCode,
NonIranPersonId,
SodourCityId,
CityId,
--MazhabId,
GenderId,
MilitaryStatusId,
MaritialStatusId,
IsEmployee,
IsTeacher,
--JobTitle,
--JobDescribtion
LastName,
FirstName,
FatherName,
--NationalityId
BirthDate_S,
SerialNumber,
NationalNumber,
PostalCode,
Phone,
Mobile,
HomeAddress,
Email
--Photo
--PhotoPath
)
values(
@PersonelCode,
@NonIranPersonId,
@SodourCityId,
@CityId,
--MazhabId,
@GenderId,
@MilitaryStatusId,
@MaritialStatusId,
@IsEmployee,
@IsTeacher,
--JobTitle
--JobDescribtion
@LastName,
@FirstName,
@FatherName,
--NationalityId
@BirthDate_S,
@SerialNumber,
@NationalNumber,
@PostalCode,
@Phone,
@Mobile,
@HomeAddress,
@Email
--Photo
--PhotoPath
)
return @@Identity
end

推荐答案

您的过程将正常进行.您必须通过具有returnvalue 参数来检索代码上的ID.
Your procedure will work fine. You have to retrieve the ID on your code by having returnvalue parameter.
<br />
<br />
Set Idcode=@@Identity


上面的语句表示您正在将标识分配给Icode变量.

@@identity将在Begin End
之间定义
谢谢
Ashish


Above statement means you are assigning the identity to Idcode variable.

@@identity will be defined in between Begin and End

Thanks
Ashish


set @result == @@ Identity
希望它能起作用...
给我详细信息,您的查询会帮助您写下_sp
set @result==@@Identity
hopes it will works...
give me details your query will hep you out write down this _sp


这篇关于sqlserver中存储过程中的插入语句出现问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆