title: SQL query to pick all active employees and terminated employees only during a specific period
body: <p>I have written a query to get both active and inactive employees from a table-</p>
  
  <pre><code>select papf.name,papf.empl_id,papf.assignment_status_type
  from per_all_people_f papf,
  per_periods_of_service ppos
  where papf.person_id = ppos.person_id
  AND (ppos.ACTUAL_TERMINATION_DATE is null or trunc(ACTUAL_TERMINATION_DATE) BETWEEN TO_CHAR (:from_date,
  'YYYY-MM-DD') AND TO_CHAR (:TO_DATE, 'YYYY-MM-DD'))
  AND ASSIGNMENT_STATUS &lt;&gt; 'Terminated - No Payroll'
  </code></pre>
  
  <p>This query will fetch all ACTIVE and INACTIVE assignments(terminated-Payroll eligible). I want that the inactive assignments/terminated-Payroll eligible assignment status is only fetched for the date passed i.e. :from_date and :to_date along with all ACTIVE assignments.</p>
  
  <p>I added a condition that <code>actual_termination_date is between these dates to pick the Terminated-Payroll</code> eligible or it is null for the active assignments but this query is fetching Terminated-Payroll eligible even when the actual_termination_date is not in those dates.</p>
  
  <p>Just to add Terminated-Payroll eligible corresponds to INACTIVE IN papf.assignment_status_type</p>