澳门金沙vip带参输出的存储过程

— =============================================
–带参输出的蕴藏进程
–测验方法:
–declare @return int
–exec 测量试验用勿删  1, @return out
–print @return
— =============================================

建一个表  t_hoteladvertise
有如下字段:
ID  自动拉长(首要)
SortID  INT (主要)
Title  NVARCHAR(50)
代码:

Create PROCEDURE [dbo].[测量试验用勿删]
@userid  int,    
@return int    out
AS
begin try
    BEGIN TRAN
    print 1/1
    COMMIT TRAN
    print ‘成功了’
END try
BEGIN catch
   ROLLBACK
   print ‘回滚了’
    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

CREATE proc sp_ehotel_DownAdvertise
@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE @TempID INT
BEGIN  TRAN
SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID
SELECT @TempSortID=max(SortID) from t_hoteladvertise where
SortID>@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@TempSortID
if @@error>0 or @@rowcount<>1
goto NeedRollBack
UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID
if @@error>0 or @@rowcount<>1
goto NeedRollBack
UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID
NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO

    SELECT
    @ErrorMessage = ERROR_MESSAGE(),
    @ErrorSeverity = ERROR_SEVERITY(),
    @ErrorState = ERROR_STATE();

CREATE proc sp_ehotel_UpAdvertise
@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE @TempID INT
BEGIN  TRAN
SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID
SELECT @TempSortID=max(SortID) from t_hoteladvertise where
SortID<@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@TempSortID
if @@error>0 or @@rowcount<>1
goto NeedRollBack
UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID
if @@error>0 or @@rowcount<>1
goto NeedRollBack
UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID
NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO
代码段:
代码: