Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:47:36+00:00 2026-06-13T02:47:36+00:00

I have one table vwuser. I want join this table with the table valued

  • 0

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:

SELECT *
FROM vwuser AS a
CROSS APPLY fnuserrank(a.userid)

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?

Data:

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 

From this 2nd record and 4th record must be selected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:47:37+00:00Added an answer on June 13, 2026 at 2:47 am

    In SQL Server 2005+ you can use this Common Table Expression (CTE) to determine the latest record by MonitorDate that doesn’t have a Rank of ‘Term’:

    WITH EmployeeData AS
    (
       SELECT *
          , ROW_NUMBER() OVER (PARTITION BY empId, ORDER BY MonitorDate DESC) AS RowNumber
       FROM vwuser AS a
       CROSS APPLY fnuserrank(a.userid)
       WHERE Rank != 'Term'
    )
    SELECT *
    FROM EmployeeData AS ed
    WHERE ed.RowNumber = 1;
    

    Note: The statement before this CTE will need to end in a semi-colon. Because of this, I have seen many people write them like ;WITH EmployeeData AS...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table with 20 columns, I want only display this data on
I have one table, t1, which has fileds called userid, week and year fields.
I have one table TABLE_SUBJECT which contain a number of subjects. I need to
I have one table TABLE_EXAM . i need to update the value of specific
i have one table named category. in this table i have two columns 1.)
I have one table that looks like this called survey_1: ================================================ |id | token
I have one table with some data. After some event I want to highlight
I have one table which display data as from Dynamic Content, I want to
I have one table with 3 rows and 3 columns. Now I want to
I have one table spread across two servers running MySql 4. I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.