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
 General SQL Server Forums
 New to SQL Server Programming
 Order By Datediff

Author  Topic 

yidrasil
Starting Member

21 Posts

Posted - 2014-01-18 : 15:39:09
Folks,

I'm looking to apply a secondary order to a select query based on the difference in hours between now and a stored date/time.

Effectively I'd like to place records with a datediff of over 2 hours to the top of the sort;

ORDER BY DATEDIFF(hour,FullLatestCallTimeStamp,Getdate() > 2) DESC

My Problem is that I get a syntax error on the '>'

I'm obviously missing an element but can't identify what...can anyone help as time is short.

Many thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-18 : 18:50:26
quote:
ORDER BY DATEDIFF(hour,FullLatestCallTimeStamp,Getdate() > 2) DESC

what are you trying to achieve with this ?

Is it the same with "ORDER BY FullLatestCallTimeStamp" ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-19 : 02:22:47
i think what you're asking for is this

ORDER BY CASE WHEN FullLatestCallTimeStamp > DATEADD(hh,-2,GETDATE()) THEN 1 ELSE 0 END DESC


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -