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 6768109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:02:04+00:00 2026-05-26T15:02:04+00:00

SCENARIO: Imagine a TABLE like this: Auto_INC, UserID_FK, CaseID_FK, Date idX userX caseX and

  • 0

SCENARIO:
Imagine a TABLE like this:

Auto_INC, UserID_FK, CaseID_FK,    Date
   idX      userX      caseX

and when it is filled, it looks like this:

   id1,     user4,     case20,   2010/01/12  
   id2,     user1,     case13,   2010/03/20  
   id3,     user2,     case10,   2010/03/22  
   id4,     user1,     case21,   2011/01/10  
   id5,     user2,      case9,   2011/01/11  
   id6,     user3,     case20,   2011/02/01  
   id7,     user1,      case9,   2011/03/25

QUESTION:
How do i get ONE CASE Record with the LAST User Assigned ??

So if one user has been assigned, it will automatically override all previous users on that case.

Something like this:

   id7,     user1,      case9,   2011/03/25  
   id2,     user1,     case13,   2010/03/20  
   id4,     user1,     case21,   2011/01/10
   id6,     user3,     case20,   2011/02/01    
   id3,     user2,     case10,   2010/03/22  

In this case User1 has been assigned to 3 cases, User2 to 2 cases but one was overridden by User1, User3 had 1 case and it did override User4 …so User4 does not get any case ..therefore it will NOT appear on the list.

NOTE BENE
Ideally we should be getting as result ..as many records as there are CASES on the original table !!!

  • 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-05-26T15:02:05+00:00Added an answer on May 26, 2026 at 3:02 pm
    declare @T table
    (
      Auto_INC int identity primary key, 
      UserID_FK int, 
      CaseID_FK int,
      [Date] date
    );
    
    insert into @T values
    (4, 20, '2010/01/12'),
    (1, 13, '2010/03/20'),
    (2, 10, '2010/03/22'),
    (1, 21, '2010/01/10'),
    (2, 9,  '2010/01/11'),
    (3, 20, '2010/02/01'),
    (1, 9,  '2010/03/25');
    
    with C as
    (
      select *,
             row_number() over(partition by CaseID_FK 
                               order by [Date] desc) as rn
      from @T
    )
    select Auto_INC, UserID_FK, CaseID_FK, [Date]
    from C
    where rn = 1;
    

    Result:

    Auto_INC    UserID_FK   CaseID_FK   Date
    ----------- ----------- ----------- ----------
    7           1           9           2010-03-25
    3           2           10          2010-03-22
    2           1           13          2010-03-20
    6           3           20          2010-02-01
    4           1           21          2010-01-10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the scenario, I have a table Day_fee(date(Date),fee(Integer)) I want to have a list
Imagine this scenario: You have a desktop and a laptop. The desktop has a
So imagine this scenario, I have a list and it has a bit of
Let's imagine this scenario Running Dropbox in my Windows Work PC, my Windows Home
Imagine this scenario: you have a WCF web service that gets hit up to
Imagine this scenario: var ass1 = Assembly.LoadFrom(@C:\Work\3.59\assembly1.dll); var ass2 = Assembly.LoadFrom(@C:\Work\3.60\assembly1.dll); Debug.Assert(ass1 != ass2);
I have seen example code that looks like this, which seems perfectly reasonable: [Authorize(Roles
Imagine this scenario: I have three tables in my database: Products , Users and
Imagine this scenario: class Page {} class Book { private $pages = array(); public
I'm looking for example of how I would solve the scenario below: Imagine my

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.