Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have records in three column like this
EmpID	       DateTime	       StatusINOUT
1	    2018-05-26 08:44          1
1	    2018-05-26 08:44	      2
2	    2018-05-28 08:44	      1
2           2018-05-28 12:44	      2                 
1           2018-05-21 08:44	      1
1	    2018-05-21 10:44	      2
2	    2018-05-23 08:44	      1
2           2018-05-23 08:44	      2



Now i want to display Status wise INTIME(1) and OUTTIME(2) it as below

Empid	INTIME(1)	           OUTIME(2)
1	 2018-05-26 08:44	 2018-05-26 08:44
2	 2018-05-28 08:44	 2018-05-28 12:44
1	 2018-05-21 08:44	 2018-05-21 10:44
2	 2018-05-23 08:44	 2018-05-23 08:44


What I have tried:

I have tried below query just it returning one row against one empID but i have multiple data against one ID of employee


SQL
select Empcode, s1 as 'INOUT (1)INTime', s2 as 'INOUT(2)OutTime' 
from 
( 
  select Empcode,Time,INOUT,Date
  from HR2 
) d 
pivot 
( 
  max(Date) 
  for INOUT in (s1,s2) 
) piv;
Posted
Updated 17-Dec-18 1:29am
v3
Comments
Maciej Los 17-Dec-18 6:19am    
You tagged question as C#, but you're using SQL.
Richard Deeming 18-Dec-18 12:05pm    
This seems to be the same as: https://www.codeproject.com/Questions/1271952/Display-data-in-gridview-from-row-to-column[^]

Presumably that's your classmate? Perhaps you should get together to work on your homework.

1 solution

Try this:
SQL
Select EmpID, 
    MIN([DateTime]) as InTime, 
    MAX([DateTime]) as OutTime
FROM (SELECT EmpID, [DateTime], CAST([DateTime] AS DATE) AS DT FROM HR2) a
GROUP BY a.EmpID, a.DT
 
Share this answer
 
Comments
Member 12314309 17-Dec-18 11:39am    
this is not my soultion
OriginalGriff 17-Dec-18 11:42am    
And does your solution work?

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