title: Sql Server 2008 sp_executesql syntax help - I think my quotes are not correct
body: <p>Using SQL Server 2008 I'm trying to build up a string and execute it with sp_executesql. I obviously have some quotes wrong. It appears to run, but the database is not dropped. Can someone help me to correct the syntax?</p>
  
  <pre><code>USE [master]
  GO
  
  DECLARE @sql NVARCHAR(500)
  SET @sql = N' IF EXISTS (SELECT NAME FROM master.sys.databases sd where name =''@DBName'') 
  BEGIN
    ALTER DATABASE [@DBName] SET  RESTRICTED_USER WITH ROLLBACK IMMEDIATE
    ALTER DATABASE [@DBName] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
    DROP DATABASE [@DBName]
  END';
  
  EXECUTE sp_executesql @sql, N'@DBName sysname', @DBName = 'ReapirInformation'
  
  GO
  </code></pre>
  
  <p>I've tried adding and removing quotation marks but I can't seem to dial in the correct mix.  Any tips or tricks are certainly welcome.</p>
  
  <p>Thanks,<br>
  ~ck in San Diego</p>