Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date Range Variables?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
32 Posts

Posted - 03/08/2013 :  06:31:02  Show Profile  Reply with Quote

I need to set up a stored procedure that runs each day and select data from a tale based on a specific date range e.g

lastoccurrence >= 'midnight the previous day' and lastoccurrence < 'midnight last night'

Obviously I can't hard code the dates in here, as that would really defeat the object of the stored procedure, so how do I go aout doing this so that the dates entered will always be between midnight he previous day and 12:00 last night? (sorry if the time range I need is a bit ambiguous, hope you understand what I'm after)..

thansk you!!

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 03/08/2013 :  06:36:43  Show Profile  Reply with Quote
use getdate() function for that

lastoccurrence >= dateadd(dd,datediff(dd,0,getdate()),-1) and lastoccurrence < dateadd(dd,datediff(dd,0,getdate()),0)

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000