title: syntax issue with alter database and set command
body: <p>Hi I'm tying to run an alter database statement and keep getting an error:
  (this is to go in a script which will run against a number of databases)</p>
  
  <pre><code>SELECT is_broker_enabled FROM sys.databases WHERE name = db_name()
  
  DECLARE @SQL NVARCHAR(1024)
  
  
  IF (SELECT is_broker_enabled FROM sys.databases WHERE name = db_name()) = 0
  BEGIN
  
      SET @SQL = N'ALTER DATABASE [' + db_name() + '] SET SINGLE_USER WITH ROLLBACK IMMEDIATE';
      SELECT @SQL;
      sp_executesql @SQL;
  
      SET @SQL = N'ALTER DATABASE [' + db_name() + '] SET ENABLE_BROKER';
      SELECT @SQL;
      sp_executesql @SQL;
  
  
      SET @SQL = N'ALTER DATABASE [' + db_name() + '] SET MULTI_USER';
      SELECT @SQL;
      sp_executesql @SQL;
  
  END 
  
  SELECT is_broker_enabled FROM sys.databases WHERE name = db_name()
  </code></pre>
  
  <p>I keep getting</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 11
    Incorrect syntax near 'sp_executesql'.
    Msg 102, Level 15, State 1, Line 15
    Incorrect syntax near 'sp_executesql'.
    Msg 102, Level 15, State 1, Line 20
    Incorrect syntax near 'sp_executesql'.</p>
  </blockquote>
  
  <p>I'm doing something dumb - but like most syntax problems looking does not give rise to seeing...</p>