[thelist] SQL Union and order by problem

Luther, Ron Ron.Luther at hp.com
Thu Oct 18 14:21:35 CDT 2007


XtiaN asked:


>>can anyone help me ?

>>select * From (
>>SELECT top 100 PERCENT a,b,c    
>>FROM tb
>>WHERE DATEDIFF(day, b ,getdate())>=3
>>order by b desc) asd
>>union all
>>select * From (
>>SELECT top 100 PERCENT a,b,c    
>>FROM tb
>>WHERE DATEDIFF(day, b ,getdate())<3
>>order by b asc) def


Hi XtiaN,


I think we have some folks who can help.

However, we might want to crosscheck and make sure we understand what
you want.

Do you really want a list of "Records that are more than 3 days old
descending by datetime stamp" added to a list of "Records that are less
than 3 days old ascending by datetime stamp"?

So if we run this query at 2pm on 18-Oct-2007 we _want_ to see something
like this???:

(Record 1) 15-Oct-2007 2pm
(Record 2) 14-Oct-2006 1pm
(Record 3) 11-Oct-2005 6pm
(...)
(Record n) 15-Oct-2007 3pm
(Record n+1) 15-Oct-2007 7pm
(Record n+2) 16-Oct-2007 4am

It just seems like a really odd thing to ask for.

I think if we better understand what you want the result to look like,
we can help get there.


Thanks,
RonL.



More information about the thelist mailing list