我有一个示例查询,我故意失败,因为数据库和表在我的测试中不存在
declare @nsql nvarchar(4000)
,@rc int
set @rc = 0
set @nsql = '
EXECUTE msdb.dbo.sp_send_dbmail
@subject = ''test sub''
,@recipients = ''joe.bloggs@myemail.com''
,@copy_recipients=''null''
,@blind_copy_recipients=''null''
,@body=''test body''
,@Query = ''select * from mydb..tlist'' ,@query_result_header =0
'
begin try
exec @RC = sp_ExecuteSQL @NSQL
end try
begin catch
set @RC=@@ERROR
end catch
print @rc
在我的 SQL2008 服务器上,我得到了这个响应
Msg 22050, Level 16, State 1, Line 0 格式查询错误,可能参数无效 RC:14661
在我的 SQL2014 服务器上,我得到了这个响应
消息 22050,级别 16,状态 1,第 0 行无法初始化 sqlcmd 库,错误号为 -2147467259。遥控:0
我的查询/问题是为什么在 SQL2014 上我得到 0 RC?它不承认失败?