Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to display the minimum valus of a date in my database and just the next value > minimum date value: my request:

SQL
select  min(Times_IN) as MinTimeIn  ,
(select min(Times_IN) from Emp_Attendance att where att.Times_IN> min (Times_IN) and month (Times_IN) ='4' and Emp_Attendance.EmpID='31'),
 max (Times_IN) as MaxTimeIn, min(Times_Out) as MinTimeOut, max(Times_Out) as MaxTimeOut,CAST(_Date AS DATE) as DateAttendance from Emp_Attendance where month (Times_IN) ='4' and Emp_Attendance.EmpID='31' group by CAST(_Date AS DATE) 



but no result
Posted
Updated 8-Jun-15 8:16am
v2

Why not
SQL
SELECT TOP 2 FROM ... ORDER BY DateColumn ASC
 
Share this answer
 
Comments
Leila Toumi 8-Jun-15 14:40pm    
I tried it but no result
What an ugly query! Where statement is used twice and many minor errors, such as incorrect usage of apostrophe with numeric data type!

SQL
SELECT MinTimeIn 
FROM (
    SELECT Times_IN AS MinTimeIn, ROW_NUMBER() OVER(ORDER BY Times_IN) AS RowNo
    FROM Emp_Attendance att
    WHERE month(Times_IN) = 4 AND EmpID=31
) AS T
WHERE RowNo IN (1,2)


Above query should return proper data: the smallest TimeIn and the second minimum value.
 
Share this answer
 
Comments
Leila Toumi 9-Jun-15 5:09am    
it works, but i need to get this list of successive dates in each date

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900