我已經通過使用UNION ALL加入了4個sql語句。SQL Union所有聲明
由於WHERE條件相同,是否可以將WHERE條件合併爲一個?
select 'Transfer In' as MovementType, * from vHRIS_StaffMovement_TransferIn
where cur_deptid in (1,2,3,4,5)
and cast(EffectiveDate as date) <='2013-08-02'
and cast(EffectiveDate as date) >= '2012-08-01'
and StaffType in (1,2,3,4,5)
union all
select 'Terminate' as MovementTyep, * from vHRIS_StaffMovement_Terminate
where cur_deptid in (1,2,3,4,5)
and cast(EffectiveDate as date) <='2013-08-02'
and cast(EffectiveDate as date) >= '2012-08-01'
and StaffType in (1,2,3,4,5)
union all
select 'New Hire' as MovementTyep, * from vHRIS_StaffMovement_NewHire
where cur_deptid in (1,2,3,4,5)
and cast(EffectiveDate as date) <='2013-08-02'
and cast(EffectiveDate as date) >= '2012-08-01'
and StaffType in (1,2,3,4,5)
union all
select 'Transfer Out' as MovementType, * from vHRIS_StaffMovement_TransferOut
where cur_deptid in (1,2,3,4,5)
and cast(EffectiveDate as date) <='2013-08-02'
and cast(EffectiveDate as date) >= '2012-08-01'
and StaffType in (1,2,3,4,5)
哎呀!毆打它! – Yonabart
太棒了。多謝。 –