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

  • Home
  • SEARCH
  • 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 7857083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:55:18+00:00 2026-06-02T20:55:18+00:00

I have the following query SELECT * FROM( SELECT CASE WHEN TO_CHAR (ADD_MONTHS(:DATEINPUT, 1),

  • 0

I have the following query

SELECT * FROM(
  SELECT
       CASE
            WHEN TO_CHAR (ADD_MONTHS(:DATEINPUT, 1), 'MM') = '10' 
            THEN
                TO_CHAR (ADD_MONTHS(:DATEINPUT, 1), 'MM')
            WHEN SUBSTR (TO_CHAR (ADD_MONTHS(:DATEINPUT, 1), 'MM'), 1, 1) = '0' 
            THEN
               SUBSTR (TO_CHAR (ADD_MONTHS(:DATEINPUT, 1), 'MM'), 2, 1)
            ELSE
               SUBSTR (TO_CHAR (ADD_MONTHS(:DATEINPUT, 1), 'MM'), 1, 2) 
         END
            AS CUR_MONTH_FRMTD,
       P.OPR_DATE,
       P.INDICE,
       P.LOAD_TYPE,
       P.CONTRACT_MONTH,
       P.CONTRACT_YEAR,
       P.VALUE,
       P.DATE_INSERTED,
       P.DATE_UPDATED
  FROM ZE_DATA.PWX_FWD_CURVE P ) Q
  WHERE
  Q.LOAD_TYPE = 'HLH'
  AND Q.INDICE = 'MidC'
  AND Q.CONTRACT_YEAR = TO_CHAR(:DATEINPUT, 'YYYY') 
  AND Q.CONTRACT_MONTH = Q.CUR_MONTH_FRMTD
  AND TO_CHAR(Q.DATE_INSERTED, 'MM') = TO_CHAR(:DATEINPUT, 'MM')
  AND TO_CHAR(Q.DATE_INSERTED, 'YY') = TO_CHAR(:DATEINPUT, 'YY')
  AND TO_CHAR(Q.DATE_INSERTED, 'DD') = TO_CHAR(:DATEINPUT, 'DD')

It works great to narrow down the record to the day it was inserted, returning just one record as required. But the problem is that no records are inserted on Saturday or Sunday, breaking the filtering’s usefulness.

For Saturday or Sunday I’d need to get Friday’s data. I thought logic such as below would work. But this can’t be done in oracle SQL.

  IF TO_CHAR(:DATEINPUT, 'DAY') = 'SATURDAY' THEN
  WHERE
  ....
  AND TO_CHAR(Q.DATE_INSERTED, 'DD') = TO_CHAR(:DATEINPUT-1, 'DD')
  ELSE IF TO_CHAR(:DATEINPUT, 'DAY') = 'SUNDAY' THEN
  WHERE
  ....
  AND TO_CHAR(Q.DATE_INSERTED, 'DD') = TO_CHAR(:DATEINPUT-2, 'DD') 

At this point I need to make this work in a select statement. Can’t use stored procedure. Can anyone think of a solution or workaround?

  • 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-02T20:55:21+00:00Added an answer on June 2, 2026 at 8:55 pm

    Instead of an IF why not just a nested or like this

    Where ...
      AND 
        (
            (TO_CHAR(:DATEINPUT, 'DAY') = 'SATURDAY' AND TO_CHAR(Q.DATE_INSERTED, 'DD') = TO_CHAR(:DATEINPUT-1, 'DD'))
            OR 
            (TO_CHAR(:DATEINPUT, 'DAY') = 'SUNDAY' AND TO_CHAR(Q.DATE_INSERTED, 'DD') = TO_CHAR(:DATEINPUT-2, 'DD'))
        )
        AND ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following query Select a,b,c, case totalcount when 0 then 0 else abcd/totalcount
I have about the following query: SELECT * FROM Product ORDER BY (SELECT CASE
I have following query working : SELECT COUNT(id), AgeRange FROM ( select id, case
i have following query working.. select count(id) , case when age < 0 then
I have the following query: Select Name, case when charindex('I',a.S_Data) > 0 then 1
I have the following query: SELECT X.ID, X.NAME, CASE R.ID WHEN NOT NULL THEN
I have the following query SELECT * FROM attend RIGHT OUTER JOIN noattend ON
I have the following query: SELECT * FROM quotes INNER JOIN quotes_panels ON quotes.wp_user_id
Suppose I have the following query: select * from A, B, C, D where
I have the following query: SELECT c.* FROM companies AS c JOIN users AS

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.