Solved

select previous date - 4 pm to 4 pm

Posted on 2011-02-22
2
301 Views
Last Modified: 2012-08-13
I want to query from my table(MS SQL) to select orderdate from lastdate @ 4 pm up to currentdate @ 4pm. What would be the query statement?

select orderdate from mytable where datediff(dd, orderdate, getdate()) = 1 ??? how about 4pm to 4 pm?
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 125 total points
ID: 34957022
check this.
select orderdate 
  from mytable 
 where orderdate between DATEADD(dd,0,datediff(dd,0,GETDATE()-1))+'16:00:00' and DATEADD(dd,0,datediff(dd,0,GETDATE()))+'16:00:00'

Open in new window

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34957117
You can calculate start and end date prior to the query to make it a bit faster
DECLARE @STARTDATE DATETIME, @ENDDATE DATETIME

SET @STARTDATE = DATEADD(DAY, -1, DATEDIFF(DAY, 0, GETDATE())) + '16:00'
SET @ENDDATE = DATEADD(DAY, 0, DATEDIFF(DAY, 0, GETDATE())) + '16:00'

select orderdate 
from mytable 
where orderdate between @STARTDATE AND @ENDDATE

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question