locked
I want to separate data from row to column against one ID? RRS feed

  • Question

  • User-367318540 posted

     I have data  like in one table ,

    DateTime                  Status        EmpId

    2018-05-28 8:00        01            2000347  

    2018-05-28 20:18       02           2000347  

    2018-05-28 8:00        01            2000348  

    2018-05-28 17:18       02           2000348

     

    now i want to separate data status 1 and 2 wise in columns  in another table using asp.net webform gridview.

    EmpID               Status (1)INTime         Status(2)OutTime    

    2000347            2018-05-28 8:00        2018-05-28 20:18

    2000348            2018-05-28 8:00        2018-05-28 17:18

     

    Date wise IN OUT pick against one employee ID this data exit in data base and transfer it into another table after converting into columns

    Kindly help .

    Sunday, December 16, 2018 11:26 AM

Answers

  • User61956409 posted

    Hi akhterr,

    You can try the following SQL Query:

    SELECT 
    EmpId, MIN(EDateTime) AS [Status (1)INTime], MAX(EDateTime) AS [Status(2)OutTime] 
    FROM [TableName] 
    GROUP BY EmpId;

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 17, 2018 9:10 AM