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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:32:13+00:00 2026-05-28T16:32:13+00:00

i have following procedure syntax working : select count(1) from from ( select id,

  • 0

i have following procedure syntax working :

select count(1) from
from
(
  select id,
  CASE
  when a >= 0 and a <= 30 then 'one'    
  when a >= 31 and a <= 60  then 'two'    
  when a >= 61 and a <= 90  then 'three'    
  else 'NO'
  END
  FROM tabel_1 t
  Where
  (
        (
           TO_CHAR(t.aDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                TO_CHAR(pTo_Date, 'YYYYMMDD')                    
                                                                 //cond1
        ) OR
        (
           TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                                 //cond2
        )OR
        (
           TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                                 //cond3
        )

        AND

        (
              p_Type = 'Admin' AND
                            t.ID > 0    //condA
        )OR
        < 0
        (
          SELECT COUNT(1)
                            FROM tab_2 t2
                            WHERE t2.ID = USER_ID AND
                                  t.ID = t2.ID              condB
        )
   )
  )


)

I mean that following clause

     Where
     ( (
                  (
              TO_CHAR(t.aDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    


              TO_CHAR(pTo_Date, 'YYYYMMDD')                    
                                                             //cond1
                ) OR
                (
                   TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD')              

                   AND

                        TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                             //cond2
                )OR
                (
                   TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') 

                    AND    
                        TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                             //cond3
                ) )

should only work for

                       ( (
                        p_Type = 'Admin' AND
                        t.ID > 0    //condA
                       )OR
                         < 0
                       (
                             SELECT COUNT(1)
                             FROM tab_2 t2
                              WHERE t2.ID = USER_ID AND
                              t.ID = t2.ID              condB
                        ) )

//p_type is a varchar which has some value to be comapred. and USER_ID is a int which holds a integer value.
i want cond1 OR con2 OR con3 to be worked only for condA OR condB..
i mean i want this result to be displayed only for admin or matched user id for id of tab_2.
i think this is not the correct one. because it work for both OR statements .
can anyone plz help.. thanx in advance

  • 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-28T16:32:14+00:00Added an answer on May 28, 2026 at 4:32 pm

    What your sub-query is doing at the moment is:

    cond1 OR cond2 OR (cond3 AND condA) OR condB
    

    That is, it will be true if either cond1, cond2 or condB is true or where cond3 and condA are both true.

    But what I think you want is:

    (cond1 OR cond2 OR cond3) AND (condA OR condB)
    

    Where it is only true if any of cond1, cond2 or cond3 is true and any of condA or condB is true.

    If that is the case then you need to put brackets around the first 3 conds and around the last two:

    select count(1) from
    from
    (
      select id,
      CASE
      when a >= 0 and a <= 30 then 'one'    
      when a >= 31 and a <= 60  then 'two'    
      when a >= 61 and a <= 90  then 'three'    
      else 'NO'
      END
      FROM tabel_1 t
      Where
      ( (
            (
               TO_CHAR(t.aDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                    TO_CHAR(pTo_Date, 'YYYYMMDD')                    
                                                                     //cond1
            ) OR
            (
               TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                    TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                                     //cond2
            )OR
            (
               TO_CHAR(t.bDate, 'YYYYMMDD') BETWEEN TO_CHAR(pFrom_Date, 'YYYYMMDD') AND    
                    TO_CHAR(pTo_Date, 'YYYYMMDD')                                                      
                                                                     //cond3
            ) )
    
            AND
    
            ( (
                  p_Type = 'Admin' AND
                                t.ID > 0    //condA
            )OR
            < 0
            (
              SELECT COUNT(1)
                                FROM tab_2 t2
                                WHERE t2.ID = USER_ID AND
                                      t.ID = t2.ID              condB
            ) )
       )
      )
    
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following procedure: CREATE PROCEDURE foo () SELECT * FROM fooBar INTO
I have the following Stored Procedure, Im looking for the correct syntax so I
Actually i have created following procedure,which is working fine. CREATE or REPLACE PROCEDURE GET_NOS(
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following SP CREATE PROCEDURE GetAllHouses set @webRegionID = 2 set @sortBy
I have a modal dialog that is created with the following: procedure TFormCompose.createParams(var Params:
I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,

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.