Getting first min date value for each employee number

I need a SQL Statement to list the employee number and the minimum date value so for the examples listed below, so that I'd get the following result:

234418         2009-01-15
245717      2009-01-15

Example of data:
234418      2009-01-15 00:03:00.000
234418      2009-01-15 14:54:00.000
234418      2009-01-15 18:02:00.000
234418      2009-01-15 19:00:00.000
------
245717      2009-01-15 08:23:00.000
245717      2009-01-15 11:54:00.000
245717      2009-01-15 12:58:00.000
245717      2009-01-15 17:13:00.000
jeffrey_b_leeAsked:
Who is Participating?
 
nmcdermaidCommented:
going by your example (all data is on the same day):
select distinct employeeid, convert(datetime,convert(varchar(8),datefield,112),112) as datefield
from yourtable

if however you have a number of days then this is mor useful:
select employeeid, min(convert(datetime,convert(varchar(8),datefield,112),112)) as datefield
from yourtable
group by employeeid
0
 
MohammedUCommented:
select empno, min(empdate)
from emp
group by empno
0
 
milduraitCommented:
Hi Jeffery

Something like this may suit your needs

SELECT
 EmpNo,  
 CAST(FLOOR(CAST(MIN(EmpDate) AS Float)) as EmpDate
FROM EmpTable
GROUP BY EmpNo
ORDER BY EmpNo
0
 
milduraitCommented:
..maybe another bracket on line 3

SELECT
 EmpNo,  
 CAST(FLOOR(CAST(MIN(EmpDate) AS Float))) as EmpDate
FROM EmpTable
GROUP BY EmpNo
ORDER BY EmpNo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.