title: SQL Server: Could not find prepared statement with handle 10 from query analizer
body: <p>I run the SQL profiler and I want to run some of the queries in the query analyser but I get an error "SQL Server: Could not find prepared statement with handle x".</p>
  
  <p>Any ideas?</p>
  
  <p>This is the SQL I have copied from the profiler:</p>
  
  <pre><code>declare @p1 int
  set @p1=10
  exec sp_prepare @p1 output,N'@P0 int,@P1 nvarchar(4000),@P2 datetime,@P3 datetime,@P4 datetime,@P5 datetime,@P6 datetime,@P7 datetime',N'SELECT * FROM SCHEDULE WITH (NOLOCK) WHERE RoomNo= @P0  AND STATUS =  @P1   AND ( (EndTimeDT &lt;=  @P2  AND EndTimeDT &gt;  @P3 ) OR (StartTimeDT &gt;=  @P4  AND StartTimeDT &lt;  @P5 )  OR (StartTimeDT &lt;=  @P6  AND EndTimeDT &gt;  @P7 ) )',1
  select @p1
  go
  exec sp_execute 10,19,N'A','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:00:00','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:30:00'
  go
  </code></pre>