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 2012 Forums
 Transact-SQL (2012)
 Date comparaison

Author  Topic 

yguyon
Starting Member

11 Posts

Posted - 2014-12-23 : 10:54:59
I have a querry that return 3 row with 3 different date in a columns.

I would like to take the latest date from these querry and the date should be smaller than a date that is stored in a temp table column..

How do I do this?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-12-23 : 16:35:42
Something like this:
SELECT MAX(DateColumn)
FROM
(
-- YOUR QUERY HERE(REMOVE THE ORDER BY CLAUSE IF YOU HAVE ONE)
) s
WHERE DateColumn < (SELECT TOP (1) aDate FROM ATempTable ORDER BY SomeColumn);
Go to Top of Page
   

- Advertisement -