I have a problem how to combine the sql statements (inner join and union all. as a Newbie in SQL. Hopefully all members can help me to solve the problems.attached herewith the SQL. The leave_Trx and leave_History contain same values that need to be union. Thank you.
select m.name, t.startdt, t.enddt,t.noday,t.createdDT,
(case when t.approveST = 'Y' then 'Approved' when t.approveST = 'N' then 'Not Approved' else 'Pending' end) as appST
from leave_Trx t
inner join leave_MType m on m.typeID = t.trxID
inner join hr_personaldata b on b.pers_ID = @pers_ID
where year(t.startdt) = @yyear
and b.pers_ID = @pers_ID and b.pers_name LIKE '%'+@pers_name+'%'
and b.pers_compID LIKE ''+@compID+''
union all
select * from leave_History h
where year(h.startdt) = @yyear and h.status = 'A'
ORDER BY t.startdt