34,576
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE aaa
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if tagid=1
begin
--处理
..
..
..
--调用
declare @msg1 varchar(100)
exec bbb @dt,21,@msg1
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,22,@msg1
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,23,@msg1
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
...
end
commit
return 1
on_error:
rollback
return -1
GO
CREATE PROCEDURE bbb
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if tagid=21
begin
set @msg='出错情况1'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if tagid=22
begin
set @msg='出错情况2'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if tagid=23
begin
set @msg='出错情况3'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
commit
return 1
on_error:
rollback
return -1
GO
--测试
declare @msg varchar(100)
set @msg = ''
exec aaa '',1, @msg output
select @msg
=========
返回成功3!
alter PROCEDURE aaa
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=1
begin
--处理
--调用
declare @msg1 varchar(100)
set @msg1 = ''
exec bbb @dt,21,@msg1 output
set @msg=@msg1
If @msg<>'返回成功1!'
goto on_error
exec bbb @dt,22,@msg1 output
set @msg=@msg1
If @msg<>'返回成功2!'
goto on_error
exec bbb @dt,23,@msg1 output
set @msg=@msg1
If @msg<>'返回成功3!'
goto on_error
end
commit
return 1
on_error:
rollback
return -1
GO
alter PROCEDURE bbb
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=21
begin
set @msg='出错情况1'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功1!'
end
if @Tagid=22
begin
set @msg='出错情况2'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功2!'
end
if @Tagid=23
begin
set @msg='出错情况3'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功3!'
end
commit
return 1
on_error:
rollback
return -1
GO
CREATE PROCEDURE aaa
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=1
begin
--处理
--调用
declare @msg1 varchar(100)
exec bbb @dt,21,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,22,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,23,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
end
commit
return 1
on_error:
rollback
return -1
GO
CREATE PROCEDURE bbb
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=21
begin
set @msg='出错情况1'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if @Tagid=22
begin
set @msg='出错情况2'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if @Tagid=23
begin
set @msg='出错情况3'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
commit
return 1
on_error:
rollback
return -1
GO
修改后的!
CREATE PROCEDURE aaa
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=1
begin
--处理
--调用
declare @msg1 varchar(100)
exec bbb @dt,21,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,22,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
exec bbb @dt,23,@msg1 output
set @msg=@msg1
If @msg<>'返回成功!'
goto on_error
end
commit
return 1
on_error:
rollback
return -1
GO
CREATE PROCEDURE bbb
@dt datetime,
@Tagid int,
@msg as varchar(100) output
AS
Begin transaction
if @Tagid=21
begin
set @msg='出错情况1'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if @Tagid=22
begin
set @msg='出错情况2'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
if @Tagid=23
begin
set @msg='出错情况3'
--处理过程
If @@error<>0
goto on_error
SET @MSG='返回成功!'
end
commit
return 1
on_error:
rollback
return -1
GO
=============
declare @msg varchar(100)
set @msg = ''
exec aaa '',1, @msg output
select @msg
RAISERROR (N'This is message %s %d.', -- Message text.
10, -- Severity,
1, -- State,
N'number', -- First argument.
5); -- Second argument.
-- The message text returned is: This is message number 5.
GO