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 2005 Forums
 Transact-SQL (2005)
 Opposite of Select Top

Author  Topic 

crackerbox
Starting Member

21 Posts

Posted - 2007-01-22 : 16:37:36
What is the opposite of Select Top? Select Bottom is not valid.

I'm trying to get the date closest to another date that is over the first date. I'm getting the closest date, but if I have two dates on the same date, I need the data from the first one it finds and my script is currently pulling the latest one of the day.

Any ideas?

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-22 : 16:44:42
top only returns a consistent row with an order by clause

so the opposite of
select top .... order by x
is
select top .... order by x desc


maybe you are looking for

select top 1 *
from tbl
where dte > @dte
order by dte



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -