Question : SQL Query: How do I get the date/time value just before the MAX record?

I'm having some issues with the query below. I would like this:
MAX(PANELLOCALTZDT) TimeOut

To actually be the second highest value in the table. I wish there was a MAX-1 but there's not. :-p
Anyhow I've tried all I can think of. Any ideas on jutting the record just before the MAX?


TIA
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
select 
[cCure].[dbo].[employeeInformation].FirstName +' '+ [cCure].[dbo].[employeeInformation].LastName AS Employee, 
TimeIn, TimeOut 
FROM [cCure].[dbo].[employeeInformation] 
INNER JOIN 
(SELECT CONVERT(varchar, CARDNUMBER, 101) AS CARDNUMBER , 
MAX(PANELLOCALTZDT) TimeIn, 
MAX(PANELLOCALTZDT) TimeOut 
FROM [cCure].[dbo].[new_Pub_Journal] 
WHERE [cCure].[dbo].[new_Pub_Journal].PANELLOCALTZDT > '1/4/2010  23:59:59.000' 
AND [cCure].[dbo].[new_Pub_Journal].PANELLOCALTZDT < '1/6/2010' Group by CARDNUMBER ) T1 
ON [cCure].[dbo].[employeeInformation].CCURECARDNUMBER = T1.CARDNUMBER 
WHERE  [cCure].[dbo].[employeeInformation].Manager = 'Smith,John' AND [cCure].[dbo].[employeeInformation].Shift LIKE '3'

Answer : SQL Query: How do I get the date/time value just before the MAX record?

What about like this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
select  
	[cCure].[dbo].[employeeInformation].FirstName +' '+ [cCure].[dbo].[employeeInformation].LastName AS 	Employee,  
	TimeIn, 
	TimeOut  
FROM [cCure].[dbo].[employeeInformation]  
INNER JOIN  
	(SELECT CONVERT(varchar, CARDNUMBER, 101) AS CARDNUMBER ,  
		MAX(PANELLOCALTZDT) TimeIn,  
		MAX(PANELLOCALTZDT) TimeOut  
	FROM [cCure].[dbo].[new_Pub_Journal] a  
	WHERE a.PANELLOCALTZDT > '1/4/2010  23:59:59.000'  
	AND a.PANELLOCALTZDT < '1/6/2010'
	and PANELLOCALTZDT <> (select max(PANELLOCALTZDT) from  [cCure].[dbo].[new_Pub_Journal] where CardNumber = a.CardNumber)
	Group by CARDNUMBER ) T1  
	
	ON [cCure].[dbo].[employeeInformation].CCURECARDNUMBER = T1.CARDNUMBER  

WHERE  [cCure].[dbo].[employeeInformation].Manager = 'Smith,John' AND 
	[cCure].[dbo].[employeeInformation].Shift LIKE '3'
Random Solutions  
 
programming4us programming4us