title: Join the table valued function in the query
body: <p>I have one table vwuser. I want join this table with the table valued function fnuserrank(userID). So I need to cross apply with table valued function:</p>
  
  <pre><code>SELECT *
  FROM vwuser AS a
  CROSS APPLY fnuserrank(a.userid)
  </code></pre>
  
  <p>For each userID it generates multiple records. I only want the last record for each empid that does not have a Rank of Term(inated).  How can I do this?</p>
  
  <p>Data:</p>
  
  <pre>
  HistoryID empid  Rank  MonitorDate
  1          A1     E1    2012-8-9
  2          A1     E2    2012-9-12 
  3          A1     Term  2012-10-13
  4          A2     E3     2011-10-09
  5          A2     TERM   2012-11-9 
  </pre>
  
  <p>From this 2nd record and 4th record must be selected.</p>