title: Using dynamic WHERE clause with sp_executesql
body: <p>I can not get dynamic where clause working. The query I use:</p>
  
  <pre><code>IF NOT EXISTS ( SELECT  *
                  FROM    sys.tables
                  WHERE   name = 'a' )
      BEGIN
          CREATE TABLE a ( a INT );
  
      END;
  DECLARE @whereClause NVARCHAR(MAX) = ' 1=1 ';
  
  DECLARE @sql NVARCHAR(MAX) = 'SELECT * FROM a WHERE @whereClause';
  
  EXEC sp_executesql @sql, N'@whereClause NVARCHAR(MAX)', @whereClause;
  
  DROP TABLE a;
  </code></pre>
  
  <p>Then additional question would be: is there any possibility to debug query that is executed with  sl_executesql?</p>