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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date and Time Column question

Author  Topic 

phate06
Starting Member

17 Posts

Posted - 2013-05-24 : 09:33:00
Hi there,

First time poster here so please be gentle

I have a basic query that I would like to display orders that have been ameneded. I do however need it to display results from today only, so in the software we user it will show a real time result of the query (clicking refresh in the software would do this)

The column is in a date time format e.g 2013-05-24 00:00:00 - I don;t seem to be able to get the desired results - below is the script minus the part in the where clause that I require.

Can anyone assist

select
OH.OrderID,
OH.Deleted,
C.Name as 'Customer Name',
OH.OrderNumber,
OH.DateTimeLastModified
from OrderHeader OH
inner join Customer C with (NOLOCK) on C.CustomerID=OH.CustomerID
where OH.DateTimeLastModified = ????
and OrderType=1
order by DateTimeLastModified asc

Thanks

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-24 : 09:37:46
-- Do like this....
WHERE DateTimeLastModified >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
AND DateTimeLastModified < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)


Refer this link for different approaches
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

--
Chandu
Go to Top of Page

phate06
Starting Member

17 Posts

Posted - 2013-05-24 : 09:46:18
Thank you so much - and thank you for the quick response - much appreciated
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-27 : 00:30:01
quote:
Originally posted by phate06

Thank you so much - and thank you for the quick response - much appreciated


welcome

--
Chandu
Go to Top of Page
   

- Advertisement -