我有一个由另一个存储过程调用的存储过程
ALTER PROCEDURE [dbo].[usp_Test]
AS
begin
declare @errorCode int
declare @lastIdentity int
select @errorCode = @@ERROR
if @errorCode=0
begin
update Vehicle set model='1996----------'
where Make='MERC'
select @errorCode = @@ERROR
select @lastIdentity = @@IDENTITY
end
print 'usp_test lastIdentity=' + convert(varchar(10), isnull(@lastIdentity,0))
print 'usp_test errorCode=' + convert(varchar(10), @errorCode)
end
Run Code Online (Sandbox Code Playgroud)
如果我像这样调用存储过程
declare @RetVal int
exec @RetVal=usp_Test
print 'return value is ' + convert(varchar(10), @RetVal)
Run Code Online (Sandbox Code Playgroud)
我收到以下消息
消息8152,级别16,状态14,过程usp_Test,行14字符串或二进制数据将被截断.该语句已终止.usp_test lastIdentity = 0 usp_test errorCode = 8152返回值为-6
通过在结尾处添加RETURN 0并在select @errorCode之后添加RETURN @errorCode ...我将有一个很好的清除方式来返回错误并随后处理它.我很惊讶,如果没有任何RETURN,我会得到-6的返回值.任何人都可以解释为什么会这样吗?
归档时间: |
|
查看次数: |
3259 次 |
最近记录: |