SQL Server UNION ALL query I use a UNION ALL query and it outputs 2 rows for the same date. I want to output only 1 row like the second picture.

Do I have to use IIF, CASE or else command?

The date, time_in, time_out fields are output from other table (main_table) and then I use a left join with the following UNION ALL query.

   (select date, time_in, time_out,leave_start,leave_end,leave_type_id, leave_type_descr
   from   table1

   union all

   select date, time_in, time_out,null,null,leave_type_id, leave_type_descr
   from  table2)
If I understand the task correctly, then try something like

WITH 
cte1 AS ( select date,  
                 time_in,  
                 time_out,  
                 leave_start,  
                 leave_end,  
                 leave_type_id,  
                 leave_type_descr
         from table1 ),
cte2 AS ( select date,  
                 time_in,  
                 time_out,  
                 null leave_start,  
                 null leave_end,  
                 leave_type_id,  
                 leave_type_descr
          from  table2 )
SELECT cte1.date, 
       cte1.time_in,  
       cte1.time_out,  
       cte1.leave_start,  
       cte1.leave_end,  
       COALESCE(cte2.leave_type_id, cte1.leave_type_id) leave_type_id,  
       COALESCE(cte2.leave_type_descr, cte1.leave_type_descr) leave_type_descr
FROM cte1
LEFT JOIN cte2
   ON cte1.date=cte2.date
  AND cte1.time_in=cte2.time_in
  AND cte1.time_out=cte2.time_out


Maybe FULL OUTER JOIN and COALESCE() for all output fields with arguments taken from both tables in proper order...