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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:57:06+00:00 2026-05-23T16:57:06+00:00

Hi all wonder if someone can lend a hand; i’ve got this tsql script

  • 0

Hi all wonder if someone can lend a hand; i’ve got this tsql script (shown below) that is currently returning data based on the owner id, if the record is active and if the record created date is less than todays date. I am then grouping the data together. What i want to achieve is return the most recent record per company.

Currently the data i return is this:

COMPANY A   JOE BLOGS   NULL    10088   Green   NULL    NULL    21/07/2007 16:57 Phone Call
COMPANY B   JOE BLOGS   NULL    10059   Green   NULL    NULL    20/07/2007 14:57 Phone Call
COMPANY B   JOE BLOGS   NULL    10059   Green   NULL    NULL    18/07/2006 09:47    E-mail
COMPANY B   JOE BLOGS   NULL    10059   Green   NULL    NULL    19/07/2006 13:19    E-mail
COMAPANY C  JOE BLOGS   NULL    10866   Green   NULL    NULL    17/08/2007 12:57 Phone Call
COMAPANY C  JOE BLOGS   NULL    10866   Green   NULL    NULL    13/08/2007 10:59    E-mail
COMAPANY C  JOE BLOGS   NULL    10866   Green   NULL    NULL    15/08/2007 14:57    E-mail

This is how i want the data to return:

COMPANY A   JOE BLOGS   NULL    10088   Green   NULL    NULL    21/07/2007 16:57 Phone Call
COMPANY B   JOE BLOGS   NULL    10059   Green   NULL    NULL    20/07/2007 14:57 Phone Call
COMAPANY C  JOE BLOGS   NULL    10866   Green   NULL    NULL    17/08/2007 12:57 Phone Call

Could someone, point me in the right direction please?

SELECT fa.name, fa.owneridname, fa.new_technicalaccountmanageridname, fa.new_customerid, fa.new_riskstatusname, 
fa.new_numberofopencases, fa.new_numberofurgentopencases, fap.actualend, fap.activitytypecodename, fap.createdby, fap.createdbyname
FROM FilteredAccount fa
INNER JOIN FilteredActivityPointer fap ON fa.accountid = fap.regardingobjectid
WHERE fa.statecodename = 'Active' 
    AND fap.ownerid = '0F995BDC'
    AND fap.createdon < getdate()

GROUP BY fa.name, fa.owneridname, fa.new_technicalaccountmanageridname, fa.new_customerid, fa.new_riskstatusname, 
fa.new_numberofopencases, fa.new_numberofurgentopencases, fap.actualend, fap.activitytypecodename, fap.createdby, fap.createdbyname
  • 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-23T16:57:06+00:00Added an answer on May 23, 2026 at 4:57 pm

    Try this

    SELECT * FROM (
    SELECT fa.name, fa.owneridname, fa.new_technicalaccountmanageridname, fa.new_customerid, fa.new_riskstatusname,  
    fa.new_numberofopencases, fa.new_numberofurgentopencases, fap.actualend, fap.activitytypecodename, fap.createdby, fap.createdbyname ,
    RN = ROW_NUMBER() OVER (PARTITION BY fa.name ORDER BY fap.createdby DESC)
    FROM FilteredAccount fa 
    INNER JOIN FilteredActivityPointer fap ON fa.accountid = fap.regardingobjectid 
    WHERE fa.statecodename = 'Active'  
        AND fap.ownerid = '0F995BDC' 
        AND fap.createdon < getdate() 
    ) a WHERE RN = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all i'm struggling with this a bit and wonder if someone could lend
I wonder, if I can inject a list of (stateless) beans, that all implementing
Hi all i wonder if someone can help, i've been given a piece of
I wonder if someone can help me. I've got a console App which I
This really, really urks me, so I hope that someone can give me a
I wonder if someone give me a solution to this. How can I get
I wonder if someone here can help me figure out this problem. I need
I wonder if someone knows where can I find a list of all the
I wonder if someone can help me - I've got a label which I
Hi all i wonder if someone can give me some help. I've written some

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.