title: error in sql query result
body: <p>I have this query</p>
  
  <pre><code>DECLARE @Base nvarchar(200) 
  
  SET @Base = 'WITH Base AS (SELECT Id, ROW_NUMBER() OVER (ORDER BY Id DESC) RN FROM'
                          + Quotename(@SampleWorkTbl) + ')
                          SELECT * INTO ##temp FROM Base'
  
  EXEC (@Base)
  
  SELECT * FROM   ##temp
  
  declare @command nvarchar(max)
  
  Set @command='SELECT TOP 15 [Name],[ImageAddress],(SELECT TOP 1 COUNT(Id) FROM' + QUOTENAME(@SampleWorkTbl) + ') as AllSampleCount FROM ' + QUOTENAME(@SampleWorkTbl) + 
              ' WHERE [Id] IN (SELECT TOP 15 Id From ##temp WHERE RN &gt; ((@Count-1)*15) ORDER BY Id DESC) ORDER BY Id DESC'
  
  exec (@command)
  
  drop table ##temp
  </code></pre>
  
  <p>I want get <code>[Name],[ImageAddress]</code> and count of Id from any table name that pass to the procedure</p>
  
  <p>but instead of <code>get name</code> , <code>image address</code> and <code>Id</code> I get this data</p>
  
  <pre><code>Id  RN
  10   1
  9    2
  8    3
  7    4
  6    5
  5    6
  4    7
  3    8
  2    9
  1    10
  </code></pre>
  
  <p>and when try again i get this error </p>
  
  <pre><code>There is already an object named '##temp' in the database.
  </code></pre>
  
  <p>@SampleWorkTbl is a name of any table that pass to the this query</p>
  
  <p>how i can fix this problem ?</p>
  
  <p>thank you for you help</p>