title: How to delete all the records in a declared table inside a storedprocedure
body: <p>I am creating a email queue to handle email sending. From that queue I'm taking X number of records and send emails according to the type field of the records.</p>
  
  <p>For that I have declared a table inside the stored procedure. When X number of records are taken I am setting the status of the record in the  <strong>EmailQ table</strong> to processing. But after sending <strong>X number of records which is now inside the declared table has to be deleted</strong>. </p>
  
  <p>For that I can use Delete but there is this <strong>TRUNCATE to delete all the records</strong> in the table. But the declared table has not identified as a Table.</p>
  
  <pre><code>WHILE EXISTS ( SELECT * FROM emailQ WHERE Status != 3)
  BEGIN
    CREATE PROCEDURE [dbo].[SendMails]
    DECLARE @Temp TABLE (......)
    --Declare all the necessary variables
  
    INSERT INTO @Temp SELECT TOP 10
    WITH (UPDLOCK, HOLDLOCK)
  
    --Update the email queue table status of selected set of records in to the @Temp
  
    DECLARE  dataSet CURSOR FORWARD_ONLY FOR (SELECT.......  FROM @Temp)
    OPEN dataSet
    FETCH NEXT FROM dataSet INTO...
  
    WHILE @@FETCH_STATUS = 0
    BEGIN
      --send mails acordingly
    END
  
    CLOSE dataSet
    DEALLOCATE dataSet
  
    --Update the email queue table status of completed set of records in to the @Temp
  
    WAITFOR DELAY...
    TRUNCATE @Temp// This is where this Temp table is not identified as a table(It says     "Incorrect sintax... Expecting a table")
  
   END
  </code></pre>
  
  <p>What is the most appropriate way to delete the records from this declared table.
  I also appreciate the comments on my way of handling the mail sending.</p>
  
  <p>Thanks.</p>