Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Getting the second recent date from a set of values.

Total Hit ( 1856)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


ANSI & T-SQL specific solutions for getting the 2nd recent date from a set of values. This can be extended to answer nth date from a set of values but the ANSI version gets unwieldy & has to be modified for bigger values.

Click here to copy the following block
-- ANSI SQL version:
SELECT MIN( t1.updatedate ) AS "2ndRecentDate"
FROM sysusers AS t1
WHERE t1.updatedate = ( SELECT MAX( t2.updatedate )
            FROM sysusers AS t2
            WHERE t2.updatedate <
               ( SELECT MAX( t3.updatedate )
                FROM sysusers AS t3 )
           )
/*
2ndRecentDate                     
------------------------------------------------------
1998-11-13 02:58:21.233
*/

GO
-- SQL70/2000 version:
SELECT TOP 1 t.updatedate AS "2ndRecentDate"
FROM (
  SELECT TOP 2 updatedate
  FROM sysusers
  ORDER BY updatedate DESC
) AS t
ORDER BY t.updatedate
/*
2ndRecentDate                     
------------------------------------------------------
1998-11-13 02:58:21.233
*/

GO


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.