Thursday, 22 August 2013

sp_executesql inside Try & Catch

sp_executesql inside Try & Catch

Begin Try
Declare @SQL NVarchar(Max)='Exec [MyLinkedServer].master.dbo.sp_executesql
N''Drop Table [tempdb].dbo.[T1]''';
Print @SQL;
Exec master.dbo.sp_executesql @SQL;
End Try
Begin Catch
Print Error_Message()
End Catch
The above script fails when the table T1 doesn't exist in MyLinkedServer
instead of being directed to Catch section. What do I miss?
Just to be clear: the original procedure constructs the @SQL dynamicaly
inside a procedure using parameters.
Thanks!

No comments:

Post a Comment