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)
 Select query to get closest future date record

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-03-28 : 23:25:34
I want to get the closest future duedate record from table mytasks


select taskid from mytasks where finishdate is null and duedate is closest to getdate() where masterrecordid = @MasterID

Can you please help, thanks.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-03-29 : 01:29:01
[code]
select top 1
taskid
from
mytasks
where
finishdate is null and
duedate > getdate() and
masterrecordid = @MasterID
order by
duedate

[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -