Need help on ANSI sql conversion

Existing Query:
select (list of columns from list of tables) from EMPANS A,EMPANS_MEMO M,QSTLINK L,QSTN Q
WHERE A.FLDCOMMENT =M.FLDREC_NUM(+) AND L.FLDFORM = ? AND L.FLDQUESTION = A.FLDQUESTION AND L.FLDROLLOVER = 'y' AND Q.FLDCODE = L.FLDQUESTION AND
(Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE <> 'y')
Ansi Converted:
select (list of columns from list of tables) from EMPANS A LEFT OUTER JOIN EMPANS_MEMO M ON (A.FLDCOMMENT =M.FLDREC_NUM)
INNER JOIN QSTLINK L ON ( A.FLDQUESTION =L.FLDQUESTION )
INNER JOIN QSTN Q ON (L.FLDQUESTION = Q.FLDCODE )
WHERE L.FLDFORM = ? AND L.FLDROLLOVER = 'y' AND
(Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE <> 'y')
could any body let me know , is this correct.
thanks for your support.

Hello, this is the ANSI equivalent:
SELECT...
FROM EMPANS A
  JOIN QSTLINK L ON ( L.FLDQUESTION = A.FLDQUESTION)
  JOIN QSTN Q ON (Q.FLDCODE = L.FLDQUESTION)
  LEFT JOIN EMPANS_MEMO M ON (A.FLDCOMMENT =M.FLDREC_NUM)
WHERE L.FLDFORM = ?
    AND L.FLDROLLOVER = 'y'
    AND (Q.FLDINACTIVE IS NULL OR Q.FLDINACTIVE 'y')

Similar Messages

  • Need Help with data type conversion

    Hello People,
    I am new to java, i need some help with data type conversion:
    I have variable(string) storing IP Address
    IPAddr="10.10.103.10"
    I have to call a library function which passes IP Address and does something and returns me a value.
    The problem I have is that external function call in this library excepts IP Address in form of a byte array.
    Here is the syntax for the function I am calling through my program
    int createDevice (byte[] ipAddress).
    now my problem is I don't know how to convert the string  IPAddr variable into a byte[] ipAddress to pass it through method.

    Class InetAddress has a method
    byte[]      getAddress() You can create an instance using the static method getByName() providing the IP address string as argument.

  • I need help on This SQL problem ASAP :)

    Hi All,
    I need help on this....
    I have a table...
    Say table name: one
    with these values
    premnum status
    1234 C
    1234 F
    1234 P
    1234 F
    5678 C
    5678 F
    5678 P
    9112 C
    9112 F
    9112 P
    9112 F
    3456 C
    3456 F
    3456 P
    7890 C
    7890 P
    7890 F
    Now, I want to output only those premnum with status = 'C' and those premnum with Status 'F' having a count > 1 (with two status = 'F')
    So the output would be something like this
    premnum status
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    I really need help on this asap...
    I need the SQL statement on this....
    Thank you in advance. :)
    Edited by: 804697 on Oct 23, 2010 9:45 PM

    Hi,
    you can use the following query.
    CREATE TABLE PREM_TEST ( premnum NUMBER , STATUS VARCHAR2(1));
    INSERT INTO PREM_TEST VALUES(1234 ,'C');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(1234 ,'P');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'C');
    INSERT INTO PREM_TEST VALUES(5678 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'C');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(9112 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'C');
    INSERT INTO PREM_TEST VALUES(3456 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'C');
    INSERT INTO PREM_TEST VALUES(7890 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'F');
    SELECT     PREMNUM , STATUS
    FROM     PREM_TEST
    WHERE     STATUS = 'C'
    OR          (PREMNUM , STATUS ) IN (     SELECT PREMNUM , STATUS
                                                 FROM     PREM_TEST
                                                 WHERE     STATUS = 'F'
                                                 GROUP BY PREMNUM , STATUS
                                                 HAVING COUNT(*) > 1
    PREMNUM S
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    9 rows selected.

  • Hi all, need help in PL SQL?

    I am new in this industry. I have my training going on ORACLE PL SQL.
    Can somebody help me out:
    1.) How do we write program to add two numbers and then printing them as output.
    2.) How do we write program to read from a file and then write to another file.
    3.) How do we write program to send an email from your program.
    4.) How do we write program to create random numbers.
    Thanks in advance. . .

    Hello;
    This forum is dedicated for Oracle Beehive, if you need help and advices on SQL/PL-SQL please open a thread on the following forum: PL/SQL
    About your third question, if you want to send an email from Beehive the best way is to perform that through the Web Services.
    Fred

  • Need Help in Simple SQL

    Hi,
    I need help. I did not know how to make this select statement run without error.
    select iif(max(numberseries) is null,'0',numberseries+ 1) from registration
    Thank

    Hi ,
    May i know what are you trying to do ,
    if you are trying to use if else in query, then it wont work
    if else is not valid in query.
    try to use decode or case , such that your need can be full filled
    Thank you
    Raj Deep.A

  • Need help on a sql query

    Hi Friends,
    I am trying to load Employees and their Assignments using APIs.
    I have various columns in my staging table like Last Name, First Name, etc., but I need help in writing query in the cursor especially for columns Emp Number and Supervisor Number.
    I have data as below
    Emp_Number     Supervisor_Number
    GE0002               GE0064
    GE0064               EG0009
    EG0009               EG0001
    100009                EG0001
    EG0001               TU0001
    Cursor I write will process the data in the same order as above, but here the problem is...
    When it processes first row, it checks for supervisor GE0064 which do not exist and so it errors out.
    Similarly for second row, it checks for supervisor EG0009 which again do not exist and so it errors out.
    So in order to prevent this, the cursor should process the rows as below
    Emp_Number     Supervisor_Number
    EG0001               TU0001
    EG0009               EG0001
    GE0064               EG0009
    GE0002               GE0064
    100009                EG0001
    By this way, Supervisor should be defined first as an employee and then it can be used as a supervisor for other employees
    is there a way that I can get the output as above(second set of data), when the table has records randomly as above(first set of data)
    Appreciate your help!
    Thanks,
    Srikanth

    Srikanth wrote:
    ... but the number of records returned by above query are lot more than number of records in the table.
    Why did the number go up?
    It's something only you can find out
    Maybe some Emp have several Supervisor(s) like
    with
    t as
    (select 'GE0002' Emp,'GE0064' Supervisor from dual union all
    select 'GE0064','EG0009' from dual union all
    select 'EG0009','EG0001' from dual union all
    select 'GE0064','100009' from dual union all
    select '100009','EG0001' from dual union all
    select 'EG0001','TU0001' from dual
    select Emp,Supervisor,lpad('_',3 * (level - 1),'_')||Emp indent
      from (select Emp,Supervisor
              from t
            union all
            select supervisor,null
              from t tt
             where not exists(select null
                                from t
                               where emp = tt.supervisor
    start with Supervisor is null
    connect by prior Emp = Supervisor
    EMP
    SUPERVISOR
    INDENT
    TU0001
    TU0001
    EG0001
    TU0001
    ___EG0001
    100009
    EG0001
    ______100009
    GE0064
    100009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    EG0009
    EG0001
    ______EG0009
    GE0064
    EG0009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    Regards
    Etbin

  • Need help in using SQL in a jsp file to compare date and time

    hi every one,
    Actually I am doing a project using JSP. I need to compare a date field in the database (MS Acess) to the current system date and time. I have to do this in a select statement.
    I have alredy defined a variable of type Date in the JSP file and I am comparing this variable to the date in the database through a select statemant.
    Here is what I am doing
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
              java.util.Date today = new java.util.Date();
              String myDate=sdf.format(today);
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= "+myDate+" ;";
    EDate is the feild in the database and it's format is (5/12/2008 5:29:47 PM) it is of type Date/Time in MS Acess.
    when I execute the query it gives the following error
    SQL error:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EDate <= 2008-10-16 08:10:07'.
    I hope any one can help me with that error and answer my question, I've tried too many things but nothing helps
    Thanks in advance :-)

    Hi,
    When the comparision is needed to be done with the current date , we don't need to send in Java
    Date then format it and compare with MS Acess Date.
    In MS Access we have Date() function which will give you the current date.
    So you can try rewriting your query as following :
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= Date() ;"; ---------------------
    Hope this helps.
    Thanks

  • Need help on Dynamic SQL Cursor in Forms

    Hi All,
    I am trying to execute Dynamic SQL Cursor in forms using EXEC_SQL built in.
    I have a cursor for example:
    'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order
    My code is
    cur_num := Exec_SQL.Open_cursor;
    sql_order := 'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order;
    EXEC_SQL.PARSE(cursor_number, sql_order);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,1,ln_Supp_Id);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,2,ls_Suppl_Name,30);
    EXEC_SQL.DEFINE_COLUMN(cur_num ,24,ls_exchange,20);
      sql_count := EXEC_SQL.EXECUTE(cur_num );
      While EXEC_SQL.FETCH_ROWS(cur_num ) > 0 Loop
            EXEC_SQL.COLUMN_VALUE(cur_num ,1,ln_Supp_Id);
            EXEC_SQL.COLUMN_VALUE(cur_num ,2,ls_Suppl_Name);
            EXEC_SQL.COLUMN_VALUE(cur_num ,24,ls_exchange);
    End Loop;
    EXEC_SQL.CLOSE_CURSOR(cur_num );
    In this case I have to write 24 Define Columns and 24 Column value. Is there any way to assign them to %rowtype at one time as I need all coulmn of the table.
    I had similar case on multiple tables.
    Please help me
    Thanks,
    Maddy

    I need this dynamic sql because p_supplier and p_order values changes at run time
    I do not understand. Is this a simplified sample or the real thing? You do know that you can pass variables to cursors:
    cursor test is
    select * from supplier where supplier = p_supplier and processing_order = p_order;
    or does e.g. p_supplier hold other parts of the query?
    cheers

  • Need help on content server conversioning formats

    Hi,
    I need a help on content server. My requirement is to convert PDF to HTML how can i achieve that wether by using IBR or by Dynamic converter and explain how to do this ?
    Srinath am fallowing you in the forum hope you can help in this...
    Thanks,
    DSV

    Hi
    Dynamic converter is the component that will be used to do the conversion from any format to HTML . So you will have to install the following to get this working :
    1. UCM Core Update patchset 6907073 which is build 74 (latest to be released)
    2. Dynamic Converter version 8.2.0.862 - This will be available in the above patchset .
    3. ContentAccess specific to your OS . This is from patchset 6899823 .
    After installing the above 3 component , restarting UCM should get the DC up and working . Then you would need to set pdf as a format to be converted to HTML (from configuration for DC admin) and it should start working fine .
    Hope it helps .
    Thanks
    Srinath

  • Need help on small sql query

    Hi,
    I have a requirement where I need to show 'F&D' string. I can explain this by below query.
    select 'F&D' from dual
    but when I run this query, toad prompts me to enter value for &D variable :( But my requirement is to show 'F&D' string.
    Can anyone please tell me what modification needs to be done to above query to get string 'F&D' as output.
    I know work around for this as below.
    select 'F'||chr(38)||'D' from dual
    I want permenant solution for this. Can anyone please help me?
    Thanks
    Shantanu

    see if below make difference
    SQL> select 'F&D' from dual ;
    Enter value for d: &D
    old   1: select 'F&D' from dual
    new   1: select 'F&D' from dual
    'F&
    F&D
    SQL> select 'F'||'&'||'D' from dual ;
    'F'
    F&D

  • Need help: Form6i PL/SQL library not found!

    New oracle user need your help:
    I installed Form6i and PO8i on NT, and config the tnsnames.ora file, they both worked fine to connect. But when I try to look into the PL/SQL library, it said PL/SQL library can not found. I deleted the classpath because with it I can't run Java, and the Sun help menu told me I can delete classpath to let it use current directory, is this the reason that Oracle can't find the library?
    One more question: when I connect to database from Form, Username, Password, then Databasename, for this last one, if I leave it blank, it will connect to the database, but if I type in my database name(the default DB name), it will again give me error message, said TNS can't resolve service. Does anybody have a clue? Thank you so much!

    The answer for on more question:
    It's not db name but service name.
    A sample in tnsname.ora:
    DKORCL[the service name].world =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dlt_db_srv[host_name])(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = dkorcl[oracle service name])
    You say,"u can leave it blank ",then u must work at the server.And the name u type in is not correct.
    May this help u!
    null

  • Need help to run sql loader from Form6i

    Hi All,
    I have some problem with the sql loader running from form 6i.
    I have done following steps for that.
    1. have created bat file to run sql loader.
    2.Alos created ctl and txt files inside the same folder.
    In the form , in button press i have written below code
    HOST('cmd /c C:\load1.bat > C:\output.txt');
    But it is giving error as -
    "Unable to open Load1.ctl."
    but i have run that bat files from command prompt ; and it is running fine.
    I guess probably it is not getting the correct path.
    Will pls help me, wt exacly I'm doing wrong?
    Rg,
    Subir

    Hi Francois,
    Thanks for reply.
    It is not a problem with the batch files. Coz, I just able to run batch files, but that is not correct solution.
    Once the host command id firing, that time it is going to path -
    "c:\orant\Form60\"
    And in this path it searching for that batch files and all the require files; but the require files are present in some different folder. So i think I need to change the path as well, but that I'm unable to do.
    To resolve the problem, I have copied all the files in "c:\orant\Form60\" folder, and then it is working.
    So I think I need to changed the path, so how to change the path. If I able to change the path I think it will worked. How to change the path?
    Best Rg,
    Subir

  • Need Help with simple date conversion

    Hi all,
    I have been creating integrations from custom Oracle tables to my Hyperion Planning application. I have most of them working, but am having issues loading dates to the application.
    The dates in the source are formatted as M/DD/YY.
    Hyperion can only recieve the dates if they are in MM-DD-YYY format. (atleast that is the error I receive when I load the interface)
    Could someone please help me build an ODI expression that will convert/format the date? My SQL is pretty weak.
    Thanks,
    Nick

    Thanks for the reply. I guess one of my issues is I am trying to do this conversion in my Sunopsis Memory Staging Area. So I guess I should be using SQL to convert the date, but I am still having issues.
    Here is the error from my log file when I attempt a straight mapping of the date...
    B9708547A,Plan1,2001-08-27,OrganizationNone,Project Type None,BegBalance,FY11,RateNone,Working,Final,Cannot load dimension member, error message is: com.hyperion.planning.HspRuntimeException: Date is incorrectly formatted, expecting "MM-DD-YYYY" format.
    Here is the SQL statement from the operator when I attempt (poor attempt) at converting the date....
    sql= """select C2_MT_PROJECTID "Project",'Plan1' "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date('MM-DD-YYYY')) "StartDate",'OrganizationNone' + ',' + 'Project Type None' + ',' + 'BegBalance' + ',' + 'FY11' + ',' + 'RateNone' + ',' + 'Working' + ',' + 'Final' "Point-of-View" from "C$_0Project" where      (1=1) """
    Here is the error from the operator get...
    org.apache.bsf.BSFException: exception from Jython:
    Traceback (innermost last):
    File "<string>", line 20, in ?
    java.sql.SQLException: Unexpected token in statement [select   C2_MT_PROJECTID    "Project",'Plan1'    "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date(]
         at org.hsqldb.jdbc.jdbcUtil.sqlException(jdbcUtil.java:67)
         at org.hsqldb.jdbc.jdbcStatement.fetchResult(jdbcStatement.java:1598)
         at org.hsqldb.jdbc.jdbcStatement.executeQuery(jdbcStatement.java:194)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
         at org.python.core.PyMethod.__call__(PyMethod.java)
         at org.python.core.PyObject.__call__(PyObject.java)
         at org.python.core.PyInstance.invoke(PyInstance.java)
         at org.python.pycode._pyx14.f$0(<string>:20)
         at org.python.pycode._pyx14.call_function(<string>)
         at org.python.core.PyTableCode.call(PyTableCode.java)
         at org.python.core.PyCode.call(PyCode.java)
         at org.python.core.Py.runCode(Py.java)
         at org.python.core.Py.exec(Py.java)
         at org.python.util.PythonInterpreter.exec(PythonInterpreter.java)
         at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:144)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    java.sql.SQLException: java.sql.SQLException: Unexpected token in statement [select   C2_MT_PROJECTID    "Project",'Plan1'    "Data Load Cube Name",CONVERT(C1_MT_PROJ_START_DT,Date(]
         at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)

  • Need Help on the sql

    Hi All,
    I need to prepare a report having monthly data. For this i am using query to pull data from the table having monthly data. Below are the complete details.
    Table Details:
    column_name data_type
    status varchar2(5)
    description varchar2(35)
    report_date date
    member_count number
    It have the sample data like below:
    status Description Report_date member_count
    0 Voluntary Disenrollment 7/1/2012
    1 Regular 7/1/2012 96540
    5 HOLD - Medi-Cal Ineligibility 7/1/2012 57
    55 Unmet Share of Cost 7/1/2012 6074
    59 HOLD - HCP Coverage Limits 7/1/2012 699
    P4 Pending Enrollment 7/1/2012
    S0 Retro - Voluntary Disenrollment 7/1/2012
    S1 Retro - Add 7/1/2012
    S9 Retro - Mandatory Disenrollment 7/1/2012
    similarly it have data for different report_date's. I need to pull data from this table like below.
    Status Description 7/1/2012 6/1/2012 5/1/2012 4/1/2012
    00 Voluntary Disenrollment 1 3
    01 Regular 96,540 96,620 96,500 96,429
    05 HOLD - Medi-Cal Ineligibility 57
    55 Unmet Share of Cost 6,074 6,652 6,899 6,922
    59 HOLD - HCP Coverage Limits 699
    P4 Pending Enrollment 1
    S0 Retro - Voluntary Disenrollment 14 13 24
    S1 Retro - Add 4,587 7,200 8,288
    S9 Retro - Mandatory Disenrollment 2 4 1
    i need to get all the details like above from 07/01/2012 to 07/01/2011. Similarly if i pull the data next month it should have all details form 08/01/2012 to 08/01/2011.
    I am using below query i am not able to get the result as intended.
    select status,description,
    max(decode(TO_CHAR(report_date,'MON'),'JAN',member_count,0)) jan,
    max(decode(TO_CHAR(report_date,'MON'),'FEB',member_count,0)) feb,
    max(decode(TO_CHAR(report_date,'MON'),'MAR',member_count,0)) mar,
    max(decode(TO_CHAR(report_date,'MON'),'APR',member_count,0)) apr,
    max(decode(TO_CHAR(report_date,'MON'),'JUN',member_count,0)) may,
    max(decode(TO_CHAR(report_date,'MON'),'JUL',member_count,0)) jun,
    max(decode(TO_CHAR(report_date,'MON'),'AUG',member_count,0)) jul,
    max(decode(TO_CHAR(report_date,'MON'),'SEP',member_count,0)) aug
    from MONTHLY_MEMBERSHIP_REPORT_834
    where report_date >=to_date('2012/01/01','yyyy/dd/mm')
    group by description,status
    order by status;
    Can some one help me on this..?
    Edited by: 948188 on Jul 23, 2012 11:36 AM
    Edited by: 948188 on Jul 23, 2012 11:36 AM

    Hi,
    Are the results you posted really what you want given the sample data you posted? If looks like all the report_dates in the sample data are in July, 2011, so I don't see how you get non-0 values in the other columns.
    To automatically get the most recent 13 months, you can do something like this:
    WITH   got_month_num       AS
         SELECT     status, description, member_count
         ,     MONTHS_BETWEEN ( TRUNC (SYSDATE,     'MONTH')
                          , TRUNC (report_date, 'MONTH')     
                          )            AS month_num
         FROM    monthly_membership_report_834
         WHERE     report_date     >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                                      , -12
         AND     report_date     <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                                      , 1
    SELECT       status,       description
    ,       MAX (DECODE (month_num,  0, member_count, 0))     AS m0
    ,       MAX (DECODE (month_num,  1, member_count, 1))     AS m1
    ,       MAX (DECODE (month_num, 11, member_count, 0))     AS m11
    ,       MAX (DECODE (month_num, 12, member_count, 0))     AS m12
    FROM       got_month_num
    GROUP BY  status,       description
    ORDER BY  status,       description
    ;Output from the sample data you posted:
    STATUS DESCRIPTION                              M0      M1     M11     M12
    00     Voluntary Disenrollment                   0       1       0
    01     Regular                                   0       1       0   98294
    05     HOLD - Medi-Cal Ineligibility             0       1       0
    55     Unmet Share of Cost                       0       1       0    5488
    59     HOLD - HCP Coverage Limits                0       1       0
    P4     Pending Enrollment                        0       1       0
    S0     Retro - Voluntary Disenrollment           0       1       0      75
    S1     Retro - Add                               0       1       0    7586
    S9     Retro - Mandatory Disenrollment           0       1       0       2If you want the column names to indicate the actual months, insrtead of having generic names like m0, then you need dynamic SQL.
    In SQL*Plus, that isn't very difficult. Here's one way, using SQL*Plus substiotution variables:
    --  Preliminary Query, to set substritution variables
    COLUMN      m0_col          NEW_VALUE     m0
    COLUMN      m1_col          NEW_VALUE     m1
    COLUMN      m11_col     NEW_VALUE     m11
    COLUMN      m12_col     NEW_VALUE     m12
    SELECT      TO_CHAR (             SYSDATE      , 'fmMM/YYYY')     AS m0_col
    ,      TO_CHAR ( ADD_MONTHS (SYSDATE,  -1), 'fmMM/YYYY')     AS m1_col
    ,      TO_CHAR ( ADD_MONTHS (SYSDATE, -11), 'fmMM/YYYY')     AS m11_col
    ,      TO_CHAR ( ADD_MONTHS (SYSDATE, -12), 'fmMM/YYYY')     AS m12_col
    FROM     dual
    --  Main Query
    WITH   got_month_num       AS
         SELECT     status, description, member_count
         ,     MONTHS_BETWEEN ( TRUNC (SYSDATE,     'MONTH')
                          , TRUNC (report_date, 'MONTH')     
                          )            AS month_num
         FROM    monthly_membership_report_834
         WHERE     report_date     >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                                      , -12
         AND     report_date     <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                                      , 1
    SELECT       status,       description
    ,       MAX (DECODE (month_num,  0, member_count, 0))     AS "&m0"
    ,       MAX (DECODE (month_num,  1, member_count, 1))     AS "&m1"
    ,       MAX (DECODE (month_num, 11, member_count, 0))     AS "&m11"
    ,       MAX (DECODE (month_num, 12, member_count, 0))     AS "&m12"
    FROM       got_month_num
    GROUP BY  status,       description
    ORDER BY  status,       description
    ;Output (when run in July, 2012)
    STATUS DESCRIPTION                          7/2012  6/2012  8/2011  7/2011
    00     Voluntary Disenrollment                   0       1       0
    01     Regular                                   0       1       0   98294
    05     HOLD - Medi-Cal Ineligibility             0       1       0
    55     Unmet Share of Cost                       0       1       0    5488
    59     HOLD - HCP Coverage Limits                0       1       0
    P4     Pending Enrollment                        0       1       0
    S0     Retro - Voluntary Disenrollment           0       1       0      75
    S1     Retro - Add                               0       1       0    7586
    S9     Retro - Mandatory Disenrollment           0       1       0       2Notice that the main query is exacly what I posted earlier, except that the column aliases reference the siubstitution variables set in the preliminary query.
    Edited by: Frank Kulash on Jul 23, 2012 4:39 PM
    Added version with dynamic column aliases

  • Need help with a SQL qurey that returns multiple rows for one record?

    I have the following query where I use a CASE WHEN clause to determine the date of a shift that begins with "FRLO" on day1 - day14 of the pay period. It works great if a schedule record contains one day that begins "FRLO", but if more than one day is "FRLO" then it only returns the first day it finds and not the others. Is there some way to get the query to return a ron for every day 1 - 14 that begins "FRLO"? System if Oracle 11G
    Order of the results is not important as this is part of a larger query that orders the results.
    Thanks in advance for any help,
    George
    SELECT s.empid,
    CASE
    WHEN UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
    THEN
    pp.startpp
    WHEN UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 1
    WHEN UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 2
    WHEN UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 3
    WHEN UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 4
    WHEN UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 5
    WHEN UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 6
    WHEN UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 7
    WHEN UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 8
    WHEN UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 9
    WHEN UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 10
    WHEN UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 11
    WHEN UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 12
    WHEN UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO'
    THEN
    pp.startpp + 13
    END
    startdate,
    NULL starttime,
    NULL endtime,
    8 hours,
    0 minutes
    FROM schedules s
    JOIN
    payperiods pp
    ON pp.periodid = s.periodid
    WHERE UPPER (SUBSTR (s.Day1, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day2, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day3, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day4, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day5, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day6, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day7, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day8, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day9, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day10, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day11, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day12, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day13, 0, 4)) = 'FRLO'
    OR UPPER (SUBSTR (s.Day14, 0, 4)) = 'FRLO';
    CURRENT OUTPUT
    EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
    753738, 3/25/2013 , , ,8 ,0
    753740, 3/25/2013 , , ,8 ,0
    753748, 3/25/2013 , , ,8 ,0
    DESIRED OUTPUT
    EMPID STARTDATE STARTTIME ENDTIME HOURS MINUTES
    753738, 3/25/2013 , , ,8 ,0
    753740, 3/25/2013 , , ,8 ,0
    753748, 3/25/2013 , , ,8 ,0
    753738, 3/26/2013 , , ,8 ,0
    753740, 3/26/2013 , , ,8 ,0
    753740, 3/28/2013 , , ,8 ,0
    753748, 1/1/2013 , , ,8 ,0
    753738, 4/3/2013 , , ,8 ,0
    753748, 4/3/2013 , , ,8 ,0
    CREATE TABLE SCHEDULES
    SCHEDULEID NUMBER(12) NOT NULL,
    EMPID NUMBER(12) NOT NULL,
    PERIODID VARCHAR2(6 BYTE) NOT NULL,
    AREAID NUMBER(12) NOT NULL,
    DAY1 VARCHAR2(50 BYTE),
    DAY2 VARCHAR2(50 BYTE),
    DAY3 VARCHAR2(50 BYTE),
    DAY4 VARCHAR2(50 BYTE),
    DAY5 VARCHAR2(50 BYTE),
    DAY6 VARCHAR2(50 BYTE),
    DAY7 VARCHAR2(50 BYTE),
    DAY8 VARCHAR2(50 BYTE),
    DAY9 VARCHAR2(50 BYTE),
    DAY10 VARCHAR2(50 BYTE),
    DAY11 VARCHAR2(50 BYTE),
    DAY12 VARCHAR2(50 BYTE),
    DAY13 VARCHAR2(50 BYTE),
    DAY14 VARCHAR2(50 BYTE),
    NOPTIND1 INTEGER DEFAULT 0,
    NOPTIND2 INTEGER DEFAULT 0,
    NOPTIND3 INTEGER DEFAULT 0,
    NOPTIND4 INTEGER DEFAULT 0,
    NOPTIND5 INTEGER DEFAULT 0,
    NOPTIND6 INTEGER DEFAULT 0,
    NOPTIND7 INTEGER DEFAULT 0,
    NOPTIND8 INTEGER DEFAULT 0,
    NOPTIND9 INTEGER DEFAULT 0,
    NOPTIND10 INTEGER DEFAULT 0,
    NOPTIND11 INTEGER DEFAULT 0,
    NOPTIND12 INTEGER DEFAULT 0,
    NOPTIND13 INTEGER DEFAULT 0,
    NOPTIND14 INTEGER DEFAULT 0
    CREATE TABLE PAYPERIODS
    PERIODID VARCHAR2(6 BYTE) NOT NULL,
    STARTPP DATE,
    ENDPP DATE
    Insert into SCHEDULES
    (SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
    DAY2, DAY3, DAY4, DAY5, DAY6,
    DAY7, DAY8, DAY9, DAY10, DAY11,
    DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
    NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
    NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
    NOPTIND13, NOPTIND14)
    Values
    (3693744, 753738, '082013', 2167, 'X',
    'FRLO<1530>', 'FRLO<1530>', '1530', '1530', '1530',
    'X', 'X', '1530', '1530', 'FRLO',
    '1530', '1530', 'X', 0, 0,
    0, 0, 0, 0, 0,
    0, 0, 0, 0, 0,
    0, 0);
    Insert into SCHEDULES
    (SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
    DAY2, DAY3, DAY4, DAY5, DAY6,
    DAY7, DAY8, DAY9, DAY10, DAY11,
    DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
    NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
    NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
    NOPTIND13, NOPTIND14)
    Values
    (3693745, 753740, '082013', 2167, 'X',
    'FRLO<1530>', 'FRLO<1530>', '1530', 'FRLO', '1530',
    'X', 'X', '1530', '1530', '1530',
    '1530', '1530', 'X', 0, 0,
    0, 0, 0, 0, 0,
    0, 0, 0, 0, 0,
    0, 0);
    Insert into SCHEDULES
    (SCHEDULEID, EMPID, PERIODID, AREAID, DAY1,
    DAY2, DAY3, DAY4, DAY5, DAY6,
    DAY7, DAY8, DAY9, DAY10, DAY11,
    DAY12, DAY13, DAY14, NOPTIND1, NOPTIND2,
    NOPTIND3, NOPTIND4, NOPTIND5, NOPTIND6, NOPTIND7,
    NOPTIND8, NOPTIND9, NOPTIND10, NOPTIND11, NOPTIND12,
    NOPTIND13, NOPTIND14)
    Values
    (3693746, 753748, '082013', 2167, 'X',
    'FRLO<1530>', '1530', '1530', '1530', '1530',
    'X', 'X', 'FRLO<1530>', '1530', 'FRLO',
    '1530', '1530', 'X', 0, 0,
    0, 0, 0, 0, 0,
    0, 0, 0, 0, 0,
    0, 0);
    COMMIT;
    Insert into PAYPERIODS
    (PERIODID, STARTPP)
    Values
    ('082013', TO_DATE('03/24/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;

    Do you have the opportunity to change the data model to have one day per row ? It would make this easier to get this result without the need for a 14-way CASE or UNION.
    If not...
    The case statement will return as soon as it matches one of the conditions. Since you want a match when any column in the row starts with FRLO you can use a UNION ALL treating each column as a separate result. There may be more efficient ways to do this, but here is one way:
    Select S.Empid,       Pp.Startpp Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day1, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+1 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day2, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+2 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day3, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+3 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day4, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+4 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day5, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+5 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day6, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+6 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day7, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+7 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day8, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+8 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day9, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+9 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day10, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+10 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day11, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+11 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day12, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+12 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day13, 0, 4)) = 'FRLO'
    Union All 
    Select S.Empid,       Pp.Startpp+13 Startdate,       Null Starttime,       Null Endtime,       8 Hours,       0 Minutes
      From Schedules S       Join  Payperiods Pp On Pp.Periodid = S.Periodid
      Where Upper (Substr (S.Day14, 0, 4)) = 'FRLO'

Maybe you are looking for

  • How do I return to the previous version of Java?

    After the latest Apple Update I have After the latest Apple-Update, I use Java 6 Update 24 for Mac OS X 10.6. If I try to upload the files in Safari and clicking the button for the upload, the window don't open to select the files. If I try the same

  • N97 speakers are an embarrassment for an Nseries. ...

    I had read on All About Symbian in his loud speaker test, that the N97 was pitiful compared to the 5800 and the N95. I couldn't come to terms with that assessment on the basis that surely Nokia wouldn't put lousy speakers on their flagship. Boy was I

  • Problem with "Capture Server Model from the Database"

    I've installed Oracle-Developer-Suite 10g and Designer 9.0.4.5.6. The repository databse is Oracle 10g and the application database is Oracle 9i (about 700 tables for the application). After I started the Designer Editor, I got the follwoing message:

  • Mac Mini No Booti

    We have a small computer lab full of identical Mac Mini's, one of which now sports a new flashing folder with a "?". I inserted the install disk and booted with the C key pressed (to no avail,) there is nothing to suggest that it realizes that a disk

  • My IPOD IS STUCK "it froze up" pls HELP

    my ipod mini is frozen it wont do anything PLS i need help