Need a single query for all IF conditions

I have the following requirements which looks at two parameter p_batch and p_frequency and frames a select to query from the Employers table.
Can I achieve all these in a single select statement? If so how to do it?
Please help.
Thank you.
IF p_batch = 1 and p_frequency = 2 then
SELECT er.employer_id
FROM employers er
WHERE SUBSTR (er.name, 1, 1) BETWEEN 'A' AND 'M'
AND er.freq_flag = 2
ORDER BY er.name asc;
ELSIF p_batch = 2 and p_frequency = 2 then
Open cursor for processing employer starting with N to Z
SELECT er.employer_id
FROM employers er
WHERE SUBSTR (er.name, 1, 1) BETWEEN 'N' AND 'Z'
AND er.freq_flag = 2
ORDER BY er.name asc;
ELSIF p_batch = 1 and p_frequency = 1 then
Open cursor for processing employer starting with A to M for all ER
SELECT er.employer_id
FROM employers er
WHERE SUBSTR (er.name, 1, 1) BETWEEN 'A' AND 'M'
ORDER BY er.name asc;
ELSIF p_batch = 2 and p_frequency = 1 then
Open cursor for processing employer starting with N to Z for all ER
SELECT er.employer_id
FROM wweb.ptei_employers er
WHERE SUBSTR (er.name, 1, 1) BETWEEN 'N' AND 'Z'
ORDER BY er.name asc;
ELSE
-- Return as no need to send any mails
END IF;

Hi,
Sure, you can do that in a single statement. Here's one way:
SELECT       employer_id
FROM       employers
WHERE       SUBSTR (name, 1, 1) BETWEEN  CASE p_batch
                             WHEN  1  THEN  'A'
                             WHEN  2  THEN  'N'
                           END
                     AND      CASE p_batch
                             WHEN  1  THEN  'M'
                             WHEN  2  THEN  'Z'
                           END
AND       (     (     p_frequency = 2
          AND     freq_flag   = 2
       OR     p_frequency  = 1
ORDER BY  name
;

Similar Messages

  • Query for all hours in a month?

    Hello,
    I was hoping someone might be able to assist. I need to query for all the hours in a user specified date range (generally a month). For example,
    a query such as:
    select all hr_end from dual where start_date between '01-feb-2010' and '28-feb-2010'
    that returns:
    feb 01 2010 01:00
    feb 01 2010 02:00
    feb 01 2010 03:00
    feb 28 2010 23:00
    feb 28 2010 24:00
    Ideally, I want to be able to run this query within a WITH clause such that I can reference the temporary table/ list of hours in a subsequent select statement quickly. Something like:
    With
    all_hrs_in_month AS
    select .....
    where start_date between '01-mar-2010' and '31-mar-2010'
    I've looked around for similar questions, but have only found ones for all the 'days' in a month using level, connect by, row_num, for which I'm honestly not too familiar with and wasn't clear as to how I could modify to my needs.
    Greatly appreciate your help with this request.
    - j
    Edited by: user12942939 on Apr 5, 2010 12:04 PM

    Hi,
    Welcome to the forum!
    WITH     got_parameters  AS
         SELECT     TO_DATE ('01-mar-2010 00:00', 'dd-mon-yyyy hh24:mi')     AS start_date
         ,     TO_DATE ('31-mar-2010 23:00', 'dd-mon-yyyy hh24:mi')     AS end_date
         FROM     dual
    ,     all_hrs          AS
         SELECT     start_date + ( (LEVEL - 1)
                        / 24
                        )     AS hr
         FROM    got_parameters
         CONNECT BY     LEVEL <= 1 + ( 24
                                   * (end_date - start_date)
    SELECT       TO_CHAR (hr, 'DD-Mon-YYYY HH24:MI')     AS h
    FROM       all_hrs
    ORDER BY  hr
    ;Output:
    H
    01-Mar-2010 00:00
    01-Mar-2010 01:00
    01-Mar-2010 02:00
    01-Mar-2010 03:00
    31-Mar-2010 22:00
    31-Mar-2010 23:00Notice that start_date and end_date don't have to span then entire month; they don't even have to be in the same month.
    If you'd rather specify just one parameter (such as a single string containing the month and year):
    WITH     got_parameters  AS
         SELECT     TRUNC ( TO_DATE (:p_month, 'mon-yyyy')
                    , 'MONTH'
                    )          AS start_date
         ,     TRUNC ( ADD_MONTHS ( TO_DATE (:p_month, 'mon-yyyy')
                                 , 1
                    , 'MONTH'
                    )          AS end_date
         FROM     dual
    ,     all_hrs          AS
         SELECT     start_date + ( (LEVEL - 1)
                        / 24
                        )     AS hr
         FROM    got_parameters
         CONNECT BY     LEVEL <= ( 24          -- NOTE: Not adding 1 here
                               * (end_date - start_date)
    SELECT       TO_CHAR (hr, 'DD-Mon-YYYY HH24:MI')     AS h
    FROM       all_hrs
    ORDER BY  hr
    How It Works
    SELECT  LEVEL  AS n
    FROM    dual
    CONNECT BY  LEVEL <= x
    ;Produces a result set consiting of the integers 1, 2, 3, ..., x.
    There's nothing magical about the dual table; you can use any table AS LONG AS THE TABLE HAS ONLY ONE ROW .
    The other examples you saw probably just added this to a starting date, to get successive days, since, in Oracle date arithmetic, dt+n is a DATE n days after dt.
    Your case is slightly more complicated, because you want to add hours, not days. Since an hour is 1/24 of a day, we multiply by 24 to find how many integers to genereate, and divide by 24 when adding that number to the base date.
    Edited by: Frank Kulash on Apr 5, 2010 3:07 PM

  • I have 7 iPhones, do I need an iTunes accounts for all of them

    I have 7 iPhones, do I need an iTunes accounts for all of them

    In that case, here is the applicable section from the iTunes Store agreement...
    If you are a commercial enterprise or educational institution, you may download and sync an App Store Product for use by either (a) a single individual on one or more iOS Devices used by that individual that you own or control or (b) multiple individuals, on a single shared iOS Device you own or control.
    So the way we have interpreted this is that each user( in a business) requires a separate iTunes account, though if the user had multiple devices that only he or she used, they need just one account for those devices.  If you are an educational institution you can check out the iOS 5 Education Deployment Guide.  Educational organizations have some different options. 
    http://images.apple.com/education/docs/IOS_5_Education_Deployment_Guide.pdf

  • HT1660 how can I use one single library for all users on the same laptop?

    how can I use one single library for all users on the same laptop?

    You are most of the way there. Each user having access to hard drive is the key. If users are limited in file privileges this is harder.
    Any files you add to your library and any files she adds to her library are available to the other. Just not automatically. Each user must add the files to their own library using the add file or add folder option from menu bar.
    What I have done is set library location to a location outside of My Documents\My Music. On my network storage I have a folder names s:\itunes. Both accounts iTunes are set to use this location for the library.

  • How to use single eventhandler for all menuitems...

    Hi all,
    I have a tray with a popup.
    Currently I have an eventhandler for every single menuitem.
    Is it also possible to provide only a single eventhandler for all of the menuitems and determine the clicked entry  with the event??
    Tried to use parameter mapping but onAction doesn't provide any parameters... Or am i wrong?!
    Additionally, is there a list populated where I can find  provided parameters for mapping?!
    Thanks in advance for replies.
    Bastian
    Message was edited by: Bastian Schnorbus

    Bastian,
    This is possible via parameter mapping.
    1. Set same action for every menu item;
    2. Add parameter, say "id" of type string to action;
    3. In wdDoModifyView write the following:
    if (firstTime)
      IWDMenuActionItem itm;
      itm = (IWDMenuActionItem)view.getElementById("<id-of-menu-item>");
      itm.mappingOfOnAction.addParameter( "id", itm.getId() );
      /* repeat for all items */
    4. In view handler you now can dispatch by "id" parameter received;
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com

  • Infotype screen headers needs to be changed for all the infotypes

    Hi Guys,
    This would be for a global implementation question.
    For the US for a particular region, the screen header needs to be changed for all the infotypes.
    The existing field (in the infotype header) is Employee Group which needs to be replaced with employment status.
    The know how to change the headers but my question is STAT2 exists in IT 0000 but does not exist in 0001, 0002 0007.........etc
    When i go to Table T588J to add an entry , Screen Header 42......,
    I get an error " No Field STAT2 exists for infotype 0001"
    No field STAT2 exists for infotype 0001.
    Message no. PG811
    Diagnosis
    No STAT2 field exists for infotype 0001.
    Procedure
    Please contact your system administrator.
    Procedure for System Administration
    In Customizing, determine the incorrect entry in Personnel
    Administration in the Header structure per infotype view, step " Determine infotype header and correct it
    I would like to have some inputs from you guys ..... Any Suggessions...
    Thanks,
    Aastha

    Hi Aastha,
    Correct me if I am wrong.
    First you need to maintain the header in T588J.
    Screen header of an infotype is defined in view V_582A_B. We can define one screen header for employee and another for applicant in view V_T588I. The header modifier selected from view V_T588I has a definition in table T588J, which finally gets shown on the screen.
    Depending on the transaction class (A = Personnel Administration, B = Recruitment) and the country grouping, a header modifier is assigned to the infotype header in the u201CHeader Modificationu201D view V_T588I.
    For example like
    Screen Header / Tr. Class / Header modifier
    00                    /        A      /  60
    In the view u201CHeader Structure per Infotypeu201D (V_582A_B), a header has been assigned to every infotype. It also determines whether the data is valid from the system date or the start date of the infotype record
    Hope this is useful.
    Regards
    RK

  • SQL Query for all Function Name attached to Responsibility

    I have a requiremnet where in the data needs to be fetched giving all details of User Name, Responsibility Name, Function_user_name at responsibility level.
    For e.g when a user logs in ORacle application and gets in to a responsibility and uses short cut key (Cntrl + L), the application lists out all the form functions, i need those form funtion for all users at responsibility level.
    follwoing is the SQL i developed but its not listing the form function when we use (cntrl + L).
    SELECT fur.user_name, fur.description, fur.responsibility_name,
    mnu.user_function_name, mnu.function_name --, mnu.TYPE, mnu.PARAMETERS
    FROM (
    SELECT /*+ ordered use_nl(ffft) */
    DISTINCT fm.menu_id, ffft.user_function_name, fff.function_name,
    fff.TYPE, fff.PARAMETERS
    FROM (select distinct menu_id
    from apps.fnd_responsibility_tl frt,
    applsys.fnd_responsibility fr
    where 1=1
    and frt.responsibility_id = fr.responsibility_id
    and frt.application_id = fr.application_id
    and frt.responsibility_name = 'SLCHR Admin Asst' ) frm,
    apps.fnd_menus fm,
    apps.fnd_form_functions fff,
    apps.fnd_form_functions_tl ffft
    WHERE 1 = 1
    --AND fm.menu_id IN (1004979, 1009084)
    AND frm.menu_id = fm.menu_id
    AND fff.function_id = ffft.function_id
    AND fm.menu_id IN (SELECT me.menu_id
    FROM apps.fnd_menu_entries me
    START WITH me.function_id = fff.function_id
    CONNECT BY PRIOR me.menu_id = me.sub_menu_id)
    ) mnu,
    (SELECT fusr.user_name, fusr.description, frv.responsibility_name, frv.menu_id
    FROM apps.fnd_responsibility_vl frv,
    apps.fnd_user_resp_groups_direct frg,
    apps.fnd_user fusr
    WHERE 1 = 1
    --and   fusr.user_name = 'JLEWIS03'
    AND frv.responsibility_name = 'SLCHR Admin Asst'
    AND frv.end_date IS NULL
    AND fusr.user_id = frg.user_id
    AND fusr.end_date IS NULL
    AND frv.responsibility_id = frg.responsibility_id
    ) fur
    WHERE 1 = 1
    AND fur.menu_id = mnu.menu_id
    Please help

    Please see these docs.
    Checking Functions Associated with a User Menu or a Responsibility [ID 948512.1]
    HOW TO GENERATE MENU TREE FOR A MENU ATTACHED TO A RESPONSIBILITY IN ORACLE APPLICATIONS 11i ? [ID 312014.1]
    Thanks,
    Hussein

  • Not allowing to query for all blocks.

    hi,
        i have a new question.
    I'm not able to query in all the fields of all blocks.
    I'm able to query only in all fields of master-block. But not able to query in fields of other blocks.
    I have set 'query all records' in the property palette to 'Yes'.
    What should i do do allow  it query & execute in all fields of all blocks?
    Thank you.

    Pl do not post duplicates - Not allowing to query for all blocks.

  • Error: "The file name needs to be specified for all documents."

    Hello
    I am trying to make sendDocument api call with the following xml:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://dto.api.echosign" xmlns:ns2="http://api.echosign" xmlns:ns3="http://dto14.api.echosign" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header/>
    <ns0:Body>
    <ns2:sendDocument>
    <ns2:apiKey>content filtered</ns2:apiKey>
    <ns2:senderInfo xsi:nil="true"/>
    <ns2:documentCreationInfo>
    <ns1:fileInfos>
    <ns1:file>CONTENT FILTERED</ns1:file>
    <ns1:fileName>test.pdf</ns1:fileName>
    <ns1:mimeType>application/pdf</ns1:mimeType>
    </ns1:fileInfos>
    <ns1:name>Test.pdf</ns1:name>
    <ns1:recipients>
    <ns3:email>[email protected]</ns3:email>
    <ns3:role/>
    </ns1:recipients>
    <ns1:reminderFrequency>DAILY_UNTIL_SIGNED</ns1:reminderFrequency>
    <ns1:signatureFlow>SENDER_SIGNS_ONLY</ns1:signatureFlow>
    <ns1:signatureType>ESIGN</ns1:signatureType>
    </ns2:documentCreationInfo>
    </ns2:sendDocument>
    </ns0:Body>
    </SOAP-ENV:Envelope>
    Which gives me an error: 'The file name needs to be specified for all documents'. Why does it happen? I specified the file name.

    I think you need to fix the recipient section, it looks incomplete. Use a tool like SoapUi to build and execute requests to the service.
    and/or the sample request in the documentation:https://secure.echosign.com/static/apiv19/sampleXml/sendDocument-request.xml

  • Check this Single place for all R12 Docs - Very Useful

    Check this,
    http://download.oracle.com/docs/cd/E18727_01/index.htm
    Description
    Oracle E-Business Suite is a comprehensive suite of integrated, global business applications which provides a customer focused strategy. Use this web site to search the various documentation types for Oracle EBS Applications. This web page provides access to documentation available in PDF and HTML formats. Use the tabs to locate and view Oracle EBS documentation.
    (Note: I have posted the same in OAF Forum, making it duplicate to share with a larger group)
    With regards,
    Kali.
    OSSi.

    Duplicate post -- Check this Single place for all R12 Docs - Very Useful
    Please post only once.
    Thanks!

  • Single query for displaying all but 1 column values for all tables

    Hi,
    All the tables have SYS_CREATION_DATE column.
    But I dont want to display this column value
    Can someone suggest some way in which i could achive this?
    Oracle version:11gR1
    OS:SunOS
    Cheers,
    Kunwar
    Edited by: user9131570 on Jul 6, 2010 7:57 PM

    user9131570 wrote:
    @Tubby
    I *want to display table-wise the values of all but 1(SYS_CREATION_DATE) columns in my database.*
    I need this in order to compare it to another database for all these values .Let me make a wild guess at what you are getting at.
    Given these two tables
    create table emp
       (empid number,
        empname varchar2(15),
        empaddr   varchar2(15),
        sys_creation_date date);
    create table dept
       (deptid number,
        deptmgr varchar2(10),
        sys_creation_date date);you want to somehow combine
    select empid,
             empname,
             empaddr
    from emp;with
    select deptid,
             deptmgr
    from dept;into a single sql statement?

  • Single query for querying three tables

    Hi All,
    We are trying to construct a sql query(a single query), which can perform the below functionality.
    Assume, that there are three tables,
    TABLE1: 3 Columns
    1) ID -> PRIMARY KEY
    2) TYPE -> Allows only values 'A' or 'B'
    3) REF_ID(this can refer to TABLE2(ID) or TABLE3(ID)).
    TABLE2: 2 Columns
    1) ID -> PRIMARY KEY
    2) DETAILS -> Any normal text
    TABLE3: 2 Columns
    1) ID -> PRIMARY KEY
    2) DETAILS -> Any normal text
    We need to come up with a query that, given TABLE1's(ID), we need to fetch the corresponding record in TABLE1, and we need to fetch the corresponding record from TABLE2 or TABLE3, depending on the below conditions.
    If the TYPE for the TABLE1's(ID) is 'A'
    Then get the details from TABLE2's by mapping TABLE1.REF_ID = TABLE2.ID
    If the TYPE for the TABLE1's(ID) is 'B'
    Then get the details from TABLE3's by mapping TABLE1.REF_ID = TABLE3.ID
    We need to accomplish all these tasks in a single query.
    Thanks for your kindly help,
    Sreenivasan

    SQL> select * from test_qry1;
    ID T REF_ID
    1 A 100
    2 A 200
    3 B 300
    SQL> select * from test_qry2;
    ID DETAILS
    100 Human Resources
    200 It Services
    300 Relationships
    SQL> select * from test_qry3;
    ID DETAILS
    100 Human Beings
    200 Conference
    300 Used things
    SQL> SELECT t1.ID,
    DECODE(t1.type,'A',( SELECT t2.details FROM test_qry2 t2 WHERE t1.ref_id = t2.id
    'B',( SELECT t3.details FROM test_qry3 t3 WHERE t1.ref_id = t3.id
    ) details
    FROM test_qry1 t1;
    ID DETAILS
    1 Human Resource
    2 It Services
    3 Used things
    Try with this query.
    Thanks,
    Vissu......

  • How to write select query for all the user tables in database

    Can any one tell me how to select the columns from all the user tables in a database
    Here I had 3columns as input...
    1.phone no
    2.memberid
    3.sub no.
    I have to select call time,record,agn from all the tables in a database...all database tables have the same column names but some may have additional columns..
    Eg: select call time, record,agn from ah_t_table where phone no= 6186759765,memberid=j34563298
    Query has to execute not only for this table but for all user tables in the database..all tables will start with ah_t
    I am trying for this query since 30days...
    Help me please....any kind of help is appreciated.....

    Hi,
    user13113704 wrote:
    ... i need to include the symbol (') for the numbers(values) to get selected..
    eg: phone no= '6284056879'To include a single-quote in a string literal, use 2 or them in a row, as shown below.
    Starting in Oracle 10, you can also use Q-notation:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements003.htm#i42617
    ...and also can you tell me how to execute the output of this script. What front end are you using? If it's SQL*Plus, then you can SPOOL the query to a file, and then execute that file, like this:
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    -- Run preliminary query to generate main query
    SPOOL     c:\my_sql_dir\all_ah_t.sql
    SELECT       'select call time, record, agn from '
    ||       owner
    ||       '.'
    ||       table_name
    ||       ' where phone_no = ''6186759765'' and memberid = j34563298'
    ||       CASE
               WHEN ROW_NUMBER () OVER ( ORDER BY  owner          DESC
                              ,        table_name      DESC
                              ) = 1
               THEN  ';'
               ELSE  ' UNION ALL'
           END     AS txt
    FROM       all_tables
    WHERE       SUBSTR (table_name, 1, 4)     = 'AH_T'
    ORDER BY  owner
    ,       table_name
    SPOOL     OFF
    -- Restore SQL*Plus features that interfere with raw output (if desired)
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    -- Run main query:
    @c:\my_sql_dir\all_ah_t.sql
    so that i form a temporary view for this script as a table(or store the result in a temp table) and my problem will be solved..Sorry, I don't understand. What is a "temporary view"?

  • What is Tcode for single delivery for all line items in PO

    Hi all,
    Sorry if it is a simple question, But I am from SD module. What is Tcode to create a single delivery documents for all line items in PO. I have 3 line items with Different materials having diffent quantities and there are different delivery dates and different delivery schedule dates. I need to create single delivery. Could you please tell me how to do it? What is the Tcode?
    Thanks
    Anil

    Hi,
    Inbound delivery T.code :VL31N,
    Regards,
    JS

  • Performance optimization on select query for all entries

    Hi All,
          I want to optimize the select query in my Program.
         The select query is taking lot of time to search the records for the given condition in the where clause
         and more interestingly there are no records fetched from the database as the where condition does not matches. 
         It is taking more than 30 min to search the record and the result is no record found.
         Below is my select query. I have also created the secondary Index for the same.
         In My opinion FOR ALL ENTRIES is taking lot of time. Because there are more than 1200 records in internal table t_ajot     
          select banfn  bnfpo     bsart      txz01   matnr   Werks   lgort     matkl    reswk   menge     meins   flief      ekorg  
              INTO CORRESPONDING FIELDS OF TABLE t_req
              FROM eban
                FOR ALL ENTRIES IN t_ajot
              WHERE matkl >= t_ajot-matkl_low
                AND matkl <= t_ajot-matkl_high
                AND werks = t_ajot-werks
                AND loekz = ' '
                AND badat IN s_badat
                AND bsart = 'NB'.  
        Please suggest.

    Hi,
    that,
    FOR ALL ENTRIES IN t_ajot
    WHERE matkl >= t_ajot-matkl_low
    AND matkl <= t_ajot-matkl_high
    AND werks = t_ajot-werks
    AND loekz = ' '
    AND badat IN s_badat
    AND bsart = 'NB'.
    looks strange.
    However:
    How does your index look like?
    What executoin plan do you get?
    How do the statistics look like?
    Whats the content of the variables t_ajot-... and s_badata?
    Kind regards,
    Hermann

Maybe you are looking for

  • Cost distribution SRM to R/3  - based on VALUE

    Hi all, We are working on SRM 5.0 and R/3 4.7.,ECS In shopping cart when the cost dsitirbution is sleected as "VALUE",when the corresponding SRM PO replicates to R/3,the cost distribution always changes to percentage/quantity....Why is that R/3 syste

  • Std purchase report

    Hi Gurus, Is there any std report which will display the values right from PR  upto MIRO. In other words i need a purchase register report. Pls help Thanks & regards Kumar

  • Cost Center in SRM

    Hi Friends, In which database table the cost centers are stored in srm? Thanks, Atanu

  • My iCloud Notes aren't getting synched to my iPhone Notes?

    I have created some notes in my iPhone. When I am checking my iCloud, my notes aren't available there. My iCloud notes are blank.

  • Mp4 video file not showing up on iphone 5.

    hey having problem with my new iphone 5 i have old movies file which i used to upload to my old iphone 4 but in iphone 5 it sycn to iphone but its not showing up on the play list on itues on iphone 5. but when i check on setteings on video on iphone