how to get list of latest record of all employee
i have a table in which i am storing multiple record of same employee and there are multiple employees also,i want to get list last record of all employees,then base on their status divide it like on job empstatus_Id 1,absent empstatus_Id 2, leave empstatus_Id 3,i want to get list of all employees latest record.

Joginder BangerPosted Feb 6, 2015, 4:40 AM
Joginder BangerPosted Feb 6, 2015, 4:39 AM
check this one.
create table #temp2(empid int,status_id int,startdate date,enddate date)
insert into #temp2 values(227,1,'2015-1-23','2015-2-02')
insert into #temp2 values(227,2,'2015-2-2','2015-2-03')
insert into #temp2 values(227,3,'2015-2-2','2015-2-04')
select top 1 empid,status_id,startdate,enddate from #temp2 order by enddate desc
Sajid HussainPosted Feb 6, 2015, 1:40 AM
emp_Id status_Id startdate EndDate
227 1 2015-1-23 2015-2-02
227 2 2015-2-2 2015-2-03
227 3 2015-2-2 2015-2-04
i just want all three status must check this last status ,and put employee into that system.
Joginder BangerPosted Feb 6, 2015, 1:11 AM
insert into tb values(3,0,0,1,getdate())
select * from tb
id job leave absent todaydate
1 1 0 0 2015-02-06
2 0 1 0 2015-02-06
3 0 0 1 2015-02-06
select * from tb where job=1 order by todaydate
id job leave absent todaydate
1 1 0 0 2015-02-06
Joginder BangerPosted Feb 6, 2015, 12:59 AM
I think in your table have a date column, you can find latest on records on the behalf of date.
like this type
select * from tablename order by DatecolumnName.