如题:存储过程带事务,如何返回值,请给个详细的例子
2 回答
慕莱坞森
TA贡献1810条经验 获得超4个赞
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[SP_ADInsert]') AND type='P') DROP PROCEDURE [dbo].[SP_ADInsert] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create PROCEDURE [dbo].[SP_ADInsert] ( @CustomerName nvarchar(200), @LoginID nvarchar(50), @AddTime datetime, @CurState smallint, @ReTurnValue int OUTPUT ) AS BEGIN TRAN Insert [AD] ( [CustomerName], [LoginID], [AddTime], [CurState] ) Values ( @CustomerName, @LoginID, @AddTime, @CurState ) set @ReTurnValue=SCOPE_IDENTITY() IF @@ERROR!=0 BEGIN set @ReTurnValue=-1 ROLLBACK END ELSE BEGIN COMMIT END GO
- 2 回答
- 0 关注
- 644 浏览
添加回答
举报
0/150
提交
取消