This is a simple Pivot solution. There is an excellent article at:
https:
Don't split the date and time into separate columns, it is bad practice. Other than that, here is a simple solution:
DECLARE @T TABLE(
Atd_ID int,
Std_ID int,
transDate date,
Detail nvarchar(10),
TimeCL time,
MessageIN bit,
MessageOut bit
)
INSERT INTO @T VALUES
(88,21,'2017-12-04','OUT','13:55:02.0000000',0,1),
(93,21,'2017-12-05','IN','09:22:56.0000000',1,0),
(96,21,'2017-12-05','OUT','10:14:33.0000000',0,1),
(98,21,'2017-12-14','IN','09:00:45.0000000',1,0),
(106,21,'2017-12-14','OUT','14:08:53.0000000',0,1),
(114,21,'2017-12-15','IN','09:30:48.0000000',1,0),
(115,21,'2017-12-15','OUT','10:03:14.0000000',0,1),
(125,21,'2017-12-16','IN','09:34:05.0000000',1,0),
(127,21,'2017-12-16','OUT','11:46:00.0000000',0,1),
(128,21,'2017-12-18','IN','08:53:55.0000000',1,0),
(137,21,'2017-12-18','OUT','14:18:11.0000000',0,1),
(142,21,'2017-12-19','IN','08:51:36.0000000',1,0),
(147,21,'2017-12-19','OUT','14:00:18.0000000',0,1),
(152,21,'2017-12-20','IN','09:10:32.0000000',1,0),
(156,21,'2017-12-20','OUT','13:10:52.0000000',0,1),
(164,21,'2017-12-21','IN','09:11:22.0000000',1,0);
SELECT * FROM
(SELECT Std_ID, transDate, MessageIN, TimeCL FROM @T)
AS s
PIVOT
(
MAX(TimeCL)
FOR MessageIN IN ([1],[0])
) AS p
Your results will look like this:
Std_ID transDate 1 0
21 2017-12-04 NULL 13:55:02.0000000
21 2017-12-05 09:22:56.0000000 10:14:33.0000000
21 2017-12-14 09:00:45.0000000 14:08:53.0000000
21 2017-12-15 09:30:48.0000000 10:03:14.0000000
21 2017-12-16 09:34:05.0000000 11:46:00.0000000
21 2017-12-18 08:53:55.0000000 14:18:11.0000000
21 2017-12-19 08:51:36.0000000 14:00:18.0000000
21 2017-12-20 09:10:32.0000000 13:10:52.0000000
21 2017-12-21 09:11:22.0000000 NULL
I hope this meets your requirements.