I have movies table with movieID,movieName and movieDate. I want to select first all movies which added in last 24 hours and order them by date and the rest order by newid().
ie.
1 babylon 28/09/2010 16:00
2.12 monekys 28/09/2010 8:00
3.se7en 25/09/2010 5:00
4.snatch 26/09/2010 18:00
How can i achieve it?
Final answer which is a combination of all other answers which all do something good...
declare @date smalldatetime
set @date = dateadd(dd,-2,getdate())
DECLARE @d AS int
SET @d = DATEPART(ss, GETDATE()) + 3
select
movieID,
movieTitle,
movieDate
from Movies
order by
case
when movieDate>@date
then movieDate end desc, movieID % @d