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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:48:30+00:00 2026-06-06T22:48:30+00:00

I am trying to produce a report which identifies client cases which were open

  • 0

I am trying to produce a report which identifies client cases which were open during each week of a year. Currently I have the following SQL which returns all clients with an indicator on whether their case was open during week 1 of our calendar. A client has two aspects which identifies if their case is open – their MOV_START_DATE and their ESU_START DATE should be greater than end date of the period, and their MOV_END_DATE/ESU_START DATE should be either null or greater than the start date of the period.

The below code works, but I thought I could just copy the left join WK1 and rename it WK2 to return information for week 2 but I’m getting an error relating to ambiguously named columns. Additionally, I’m guessing that having 52 (one for each week) left joins on a report isn’t particularly advisable, so again I’m wondering if there is a better way of achieving this?

    SELECT
A.ESU_PER_GRO_ID,
A.ESU_ID,
A.STATUS,
B.MOV_ID,
B.MOV_START_DATE,
B.MOV_END_DATE,
A.ESU_START_DATE,
A.ESU_END_DATE,
LS.CLS_DESC,
nvl2(wk1.PRD_PERIOD_NUM,'Y','N') as "Week1"

FROM
A

LEFT JOIN B ON B.MOV_PER_GRO_ID = A.ESU_PER_GRO_ID

LEFT JOIN LS ON LS.CLS_CODE = A.STATUS

LEFT JOIN O_PERIODS WK1 ON B.MOV_START_DATE < WK1.PRD_END_DATE
AND (B.MOV_END_DATE IS NULL OR B.MOV_END_DATE > WK1.PRD_START_DATE)
AND A.ESU_START_DATE  < WK1.PRD_END_DATE
AND (A.ESU_END_DATE IS NULL OR A.ESU_END_DATE > WK1.PRD_START_DATE)
AND PRD_CAL_ID = 'E1190' AND WK1.PRD_PERIOD_NUM = 1 AND WK1.PRD_YEAR = 2012

WHERE
B.MOV_START_DATE  Is Not Null  
AND A.STATUS <> ('X') 

Hopefully I have provided enough information, but if not, I am happy to answer questions. Thanks!

Sample Data (Produced by above query)

 P ID    ESU_ID STATUS  MOV_ID  M_START     M_END   DESC    Week1
 1      ESU1       New      1M  01/01/2012           Boo    Y
 2      ESU2       New     2M   01/03/2012           Boo    N

Desired output (Week1 – Week 52)

 P ID    ESU_ID STATUS  MOV_ID  M_START     M_END   DESC    Week1 Week2
 1      ESU1       New     1M   01/01/2012           Boo    Y     Y
 2      ESU2       New     2M   01/03/2012           Boo    N     N
  • 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-06T22:48:31+00:00Added an answer on June 6, 2026 at 10:48 pm

    I suspect that the reason creating a WK2 join like WK1 didn’t work was that the column PRD_CAL_ID didn’t have a table alias on it. However, as you guessed, 52 joins is probably not going to perform very well. Try the following:

    SELECT A.ESU_PER_GRO_ID,    
           A.ESU_ID,    
           A.STATUS,    
           B.MOV_ID,    
           B.MOV_START_DATE,    
           B.MOV_END_DATE,    
           A.ESU_START_DATE,    
           A.ESU_END_DATE,    
           LS.CLS_DESC,    
           'Week' || TRIM(TO_CHAR(pd.PRD_PERIOD_NUM)) WEEK_DESC
      FROM A
      LEFT JOIN B
        ON B.MOV_PER_GRO_ID = A.ESU_PER_GRO_ID    
      LEFT JOIN LS
        ON LS.CLS_CODE = A.STATUS    
      LEFT JOIN O_PERIODS pd
        ON B.MOV_START_DATE < pd.PRD_END_DATE AND
           (B.MOV_END_DATE IS NULL OR
            B.MOV_END_DATE > pd.PRD_START_DATE) AND
           A.ESU_START_DATE  < pd.PRD_END_DATE AND
           (A.ESU_END_DATE IS NULL OR
            A.ESU_END_DATE > pd.PRD_START_DATE)
    WHERE B.MOV_START_DATE Is Not Null AND
          A.STATUS <> ('X') AND
          pd.PRD_CAL_ID = 'E1190' AND
          pd.PRD_YEAR = 2012
    ORDER BY WEEK_DESC
    

    This produces slightly different results than your original query, having a WEEK_DESC instead of trying to create 52 different columns, one for each week, but I think it will perform better.

    Share and enjoy.

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

Sidebar

Related Questions

I'm trying to produce a report that shows, for each Part No, the results
The situation: I have MySQL 5. I am trying to produce a report of
I have an application which relies on a soap server to produce content. Additionally
I am trying to produce a sql query based report that will allow a
I have a few Munin plugins which report stats from an Autonomy database. They
I'm trying to produce a report that has multiple grouping but does not just
I'm trying to understand how to produce a report of what's included in a
I'm trying to produce a report using c#. First part of the report gets
I'm trying to produce a Winforms report in my .NET application. Our users want
I'm currently struggling with Oracle Apex. I'm trying to create an application which enables

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.