Please help in to merge this 2 queries, I have try using UNION and get error for the result
— First Query
select p.pegawainama,r.pegawainid, sum(cast(round(r.besarpotongan,0) as int)) as totalpotnondinas
from
rpotongan r
inner join
pegawai p on p.pegawainid=r.pegawainid
where
r.nojenpot not in (1,7,6,12,14)
--and r.pegawainid = '6290134A'
and r.bulan = '3'
and r.tahun = '2012'
and p.kodebayar = '152012'
group by
r.pegawainid,
p.pegawainama
order by
p.pegawainama,
sum(cast(round(r.besarpotongan,0) as int))
— Second Query
select p.pegawainama, r.pegawainid, sum(cast(round(r.besarpotongan,0) as int)) as totalpotdinas from rpotongan r
inner join
pegawai p on p.pegawainid=r.pegawainid
where
r.nojenpot in (1,7,6,12,14)
--and r.pegawainid = '6290134A'
and r.bulan = '3'
and r.tahun = '2012'
and p.kodebayar = '152012'
group by
r.pegawainid,
p.pegawainama
order by
p.pegawainama,
sum(cast(round(r.besarpotongan,0) as int))
To use
UNION, you need to have the same column names, so you can’t havetotalpotnondinasin one query andtotalpotdinasin the other.What you can do is call both columns
totalsand add an additional column that indicates which query was the source of the data. For example:— Second Query
If you omit the synthetic
srccolumn,UNIONwill merge identical results.