Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:34:54+00:00 2026-06-10T14:34:54+00:00

I am creating a email queue to handle email sending. From that queue I’m

  • 0

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.

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 EmailQ table to processing. But after sending X number of records which is now inside the declared table has to be deleted.

For that I can use Delete but there is this TRUNCATE to delete all the records in the table. But the declared table has not identified as a Table.

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

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.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:34:55+00:00Added an answer on June 10, 2026 at 2:34 pm

    You should do it with delete

    DELETE FROM @Temp
    

    Check related question

    SQL Server, temporary tables with truncate vs table variable with delete

    More on Truncate and Temp Tables

    TRUNCATE TABLE

    Should I use a #temp table or a @table variable?

    UPDATE:

    Truncate table won’t work with declared table variable. You should use #Temp table instead or deleting rows instead of trancating. Check related question for more info.

    UPDATE 2:

    Great answer by Martin Smith

    What’s the difference between a temp table and table variable in SQL Server?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say your creating an application that needs to send you an email monthly.
I'm working on creating a windows service that will send emails to a customer
i am creating an email client that sends e-mail address from server ip instead
i am creating an email client that sends e-mail address from server ip instead
I am creating the email format from my code-behind. In that I am using
My requirement is that I want to send email from MS SQL Server whenever
I'm creating an Outlook add-in that can save selected emails to an external database.
I'm creating email notification system on my site to send email to the users
I am creating an email software which send email to some accounts. I want
I have a Workflow 4.0 app that generates emails. In a dialog for creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.