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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:11:17+00:00 2026-05-27T17:11:17+00:00

This is continuing on from a query that was solved previously via stackoverflow (

  • 0

This is continuing on from a query that was solved previously via stackoverflow (Returning nearest date to date in a different table), however, I now wish to develop it a little further.

The SQL I have is this:

SELECT *
FROM (SELECT O_ASSESSMENTS.ASM_SUBJECT_ID as "P Number", 
             O_ASSESSMENTS.ASM_ID as "Assessment ID", 
             O_ASSESSMENTS.ASM_START_DATE as "Assessment Start",  
             O_ASSESSMENTS.ASM_END_DATE as "Assessment End", 
             O_SERVICE_EVENTS.SEV_ID as "Event ID", 
             O_SERVICE_EVENTS.SEV_ACTUAL_DATE as "Event Start", 
             O_SERVICE_EVENTS.SEV_OUTCOME_DATE as "Event End",
             ROUND(O_ASSESSMENTS.ASM_START_DATE -O_SERVICE_EVENTS.SEV_ACTUAL_DATE,0) as "Likely",
             row_number() over(PARTITION BY  O_ASSESSMENTS.ASM_ID                                    
                               ORDER BY abs(O_ASSESSMENTS.ASM_START_DATE -  O_SERVICE_EVENTS.SEV_ACTUAL_DATE))as "Row Number"            
      FROM O_ASSESSMENTS 
      JOIN O_SERVICE_EVENTS
        ON O_ASSESSMENTS.ASM_SUBJECT_ID = O_SERVICE_EVENTS.SEV_SUBJECT_ID
      Where O_SERVICE_EVENTS.SEV_CODE IN ('ICS_E3','CPINVEST') AND 
            O_ASSESSMENTS.ASM_QSA_ID  IN ('AA1329','AA521') )
WHERE "Row Number" = 1

Basically, we have two tables – o_assessments and o_service_events, and this SQL is returning the nearest service event to the assessment. Now I want to include some more contexual information into the query to make it more helpful for the end user – namely the team name and the worker name.

Unfortunately, team and worker are in a different table again (o_responsibilities), and are linked to the o_assessments by asm_id to res_rec_id.

Problem is, I’m really not sure how to call this table into the above sql – so any advice would really be appreciated!

I was also wondering if it would be possible to tweak the existing query to only return corresponding events when the ‘likely’ field had a difference of 0 (as anything greater is probably not related to that particular assessment). I know I can add it into the where, but if I add the line

and "Likely" = 0

it only returns assessments with an event, which wouldn’t highlight any issues (i.e. assessments without corresponding events).

I’m learning all the time with SQL, but there are a lot of things that just seem really beyond me at the moment, so any advice is much appreciated! I wasn’t sure whether to amend my original query or to start a new one, so I hope I haven’t infringed on any rules inadvertently.

Edit:

Okay, following Mark’s solution, this is what I have working.

SELECT 
* 
FROM 
(SELECT 
OAS.ASM_SUBJECT_ID as "P Number",
OAS.ASM_ID as "Assessment ID",
OAS.ASM_START_DATE as "Assessment Start", 
OAS.ASM_END_DATE as "Assessment End",
OAS.ASM_AUTH_DATETIME as "Authorisation Date",
nvl(olm_bo.get_ref_desc(OAS.ASM_OUTCOME,'ASM_OUTCOME'),'') as "Outcome",
nvl(olm_bo.get_org_name(ORE.RES_PARTY_OUN_ID),'') as "Team",
nvl(olm_bo.get_per_name(ORE.RES_PARTY_ID),'') as "Worker",
OSE.SEV_ID as "Event ID",
OSE.SEV_ACTUAL_DATE as "Event Start",
OSE.SEV_OUTCOME_DATE as "Event End",
ROUND(OAS.ASM_START_DATE -OSE.SEV_ACTUAL_DATE,0) as "Likely",
row_number() over(PARTITION BY  OAS.ASM_ID                   
ORDER BY 
abs(OAS.ASM_START_DATE -  OSE.SEV_ACTUAL_DATE))as "Row Number"
FROM O_ASSESSMENTS OAS      
INNER JOIN O_RESPONSIBILITIES ORE ON OAS.ASM_ID = ORE.RES_REC_ID
AND ORE.RES_PARTY_OUN_ID = 'TEAM'
LEFT JOIN O_SERVICE_EVENTS OSE ON OAS.ASM_SUBJECT_ID = OSE.SEV_SUBJECT_ID 
AND            
OSE.SEV_CODE IN ('EVENT') 
AND             
ROUND(OAS.ASM_START_DATE - OSE.SEV_ACTUAL_DATE,0) >= -7
AND
ROUND(OAS.ASM_START_DATE - OSE.SEV_ACTUAL_DATE,0) <= 7
Where OAS.ASM_QSA_ID  IN ('ACODE')
AND
nvl(olm_bo.get_ref_desc(OAS.ASM_OUTCOME,'ASM_OUTCOME'),'') <> 'Abandon' ) WHERE "Row Number" = 1 
  • 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-27T17:11:18+00:00Added an answer on May 27, 2026 at 5:11 pm

    Try:

    SELECT *
    FROM (SELECT OAS.ASM_SUBJECT_ID as "P Number", 
                 OAS.ASM_ID as "Assessment ID", 
                 OAS.ASM_START_DATE as "Assessment Start",  
                 OAS.ASM_END_DATE as "Assessment End", 
                 ORE.TEAM,
                 ORE.WORKER,
                 OSE.SEV_ID as "Event ID", 
                 OSE.SEV_ACTUAL_DATE as "Event Start", 
                 OSE.SEV_OUTCOME_DATE as "Event End",
                 ROUND(OAS.ASM_START_DATE -OSE.SEV_ACTUAL_DATE,0) as "Likely",
                 row_number() over(PARTITION BY  OAS.ASM_ID                                    
                                   ORDER BY abs(OAS.ASM_START_DATE -  OSE.SEV_ACTUAL_DATE))as "Row Number"            
          FROM O_ASSESSMENTS OAS
          LEFT JOIN O_RESPONSIBILITIES ORE
            ON OAS.ASM_ID = ORE.RES_REC_ID
          LEFT JOIN O_SERVICE_EVENTS OSE
            ON OAS.ASM_SUBJECT_ID = OSE.SEV_SUBJECT_ID AND
               OSE.SEV_CODE IN ('ICS_E3','CPINVEST') AND 
               ROUND(OAS.ASM_START_DATE - OSE.SEV_ACTUAL_DATE,0) = 0
          Where OAS.ASM_QSA_ID  IN ('AA1329','AA521') )
    WHERE "Row Number" = 1
    

    Note that this assumes that RES_REC_ID is a unique identifier on O_RESPONSIBILITIES.

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

Sidebar

Related Questions

I am trying to write a SQL query that returns rows from a table
This is continuing questions from Selecting the highest salary Assuming a table ' wagetable
Continuing from this question : When I am trying to do fopen on Windows,
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
I need to execute this query to find out the next auto_increment value that
I have a VB .Net linq query that I want to return values from
On a site that I'm working on, I'm displaying results from a database query.
I have a variable that I got out of the database table like this:
I have select query that fetch record based on a condition Select * from
This task occurs from time to time in my projects. I need to handle

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.