title: Using RETURN in dynamic SQL to exit stored procedure
body: <p>I am trying to use something like below in my stored procedure to exit when a certain condition is met, but the code after the return gets executed. Is there something wrong my script?</p>
  
  <pre><code>declare @DBName sysname
  set @DBName ='Test_DB'
  SET @sql='IF OBJECT_ID('''+@DBName +''',''U'') is null' + CHAR(10)+  'RETURN;' 
  EXEC (@sql)
  </code></pre>