Reputation: 11
I have an example query that I am purposely failing as the db and table doesn't exist as part of my test
declare @nsql nvarchar(4000)
,@rc int
set @rc = 0
set @nsql = '
EXECUTE msdb.dbo.sp_send_dbmail
@subject = ''test sub''
,@recipients = ''[email protected]''
,@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
On my SQL2008 server I get this response
Msg 22050, Level 16, State 1, Line 0 Error formatting query, probably invalid parameters RC:14661
On my SQL2014 server I get this response
Msg 22050, Level 16, State 1, Line 0 Failed to initialize sqlcmd library with error number -2147467259. RC:0
My query/issue is why on SQL2014 am I getting a 0 RC? Its not recognising the failure?
Upvotes: 1
Views: 290