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 116833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:14:25+00:00 2026-05-11T03:14:25+00:00

I need to create a stored procedure that upon exceution checks if any new

  • 0

I need to create a stored procedure that upon exceution checks if any new rows have been added to a table within the past 12 hours. If not, an warning email must be sent to a recipient.

I have the procedures for sending the email, but the problem is the query itself. I imagine I’d have to make an sql command that uses current date and compares that to the dates in the rows. But I’m a complete beginner in SQL so I can’t even use the right words to find anything on google.

Short version:

Using MS SQL Server 2005, how can I check against the dates, then return a result based on whether new rows were created within the last 12 hours, and use that result to decide whether or not to send email?

  • 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. 2026-05-11T03:14:26+00:00Added an answer on May 11, 2026 at 3:14 am

    Say your date field in the table is ‘CreateDate’ and it’s of type DateTime. Your time to compare with is: GETDATE() (which returns date + time) To get the datetime value of 12 hours before that, is done using DATEADD: DATEADD(hour, -12, GETDATE())

    so if we want the # of rows added in the last 12 hours, we’ll do:

    SELECT COUNT(*) FROM Table WHERE CreateDate >= DATEADD(hour, -12, GETDATE()) 

    in your proc, you’ve to store the result of this query into a variable and check if it’s > 0, so:

    DECLARE @amount int SELECT @amount=COUNT(*) FROM Table WHERE CreateDate >= DATEADD(hour, -12, GETDATE()) 

    and then you’ll check the @amount variable if it’s > 0.

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

Sidebar

Related Questions

I want to create generic function that will need only parameter as Stored procedure
I need create a SQL Server stored procedure that does the following: Take an
We have a stored procedure that uses UDFs. We need to modify the content
I need to create a stored procedure one time and in one place only
I need to create a sql stored procedure (Sql Server 2008 - T-SQL) which
I need a help with a complicated select query.I have message table CREATE TABLE
I am having the stored procedure. For that i need to pass the Database
I need to create a database table to store different changelog/auditing (when something was
I need to create a configuration section, that is able to store key-value pairs
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>

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.