SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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  

jun0
Starting Member

United Kingdom
32 Posts

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

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!!

visakh16
Very Important crosS Applying yaK Herder

India
52309 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
http://visakhm.blogspot.com/

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