-3

I have an employee table with below details

EMPid   TimeIn.             TimeOut
---------------------------------------------
123     1 Jan 2016 10:10    NULL
123     NULL                1 Jan 2016 18:30
123     1 Jan 2016 9:10     NULL
123     NULL                1 Jan 2016 18:00

I need output with order by time in ascending order. Below is sample output.

EMPid     TimeIn.              TimeOut
------------------------------------------------
123       1 Jan 2016 9:10      NULL
123       1 Jan 2016 10:10     NULL 
123       NULL                 1 Jan 2016 18:00
123       NULL                 1 Jan 2016 18:30
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

2

SELECT * FROM Employee ORDER BY TimeIn, TimeOut

eigenharsha
  • 2,051
  • 1
  • 23
  • 32
-3

Try this,

DECLARE @employee TABLE (EMPid INT,TimeIn DATETIME,TimeOut DATETIME)

    INSERT INTO @employee(EMPid,TimeIn,TimeOut)
    VALUES(123,' 1 Jan 2016 10:10',    NULL),
    (123,NULL,  '1 Jan 2016 18:30'),
    (123,' 1 Jan 2016 9:10'  ,   NULL),
    (123, NULL     ,           '1 Jan 2016 18:00')


SELECT * FROM @employee ORDER BY ISNULL(TimeIn,TimeOut)
SHD
  • 399
  • 3
  • 12