SQL Server Forums
Profile | Register | 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?
 New Topic  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

52325 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  
 New 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.1 seconds. Powered By: Snitz Forums 2000