Date Functions in Discoverer Query

Hi,
It has been a while since I logged into the forum. Sorry at present my contribution is only to get help. Hope to help others in future.
Here is teh problem I am facing.
We have frequent requirement to get the sales comparison by last year to this year
in Week to Date, Month to Date, Year to Date timeline.
To accomplish I use Custom Date functions in my Discoverer which results in query like below
SELECT o100229.curr_division_code,
SUM (DECODE (discotw_admin.fiscal_cal_by_wk.flyrweek (:fyrweek),
o100059.fiscal_year_week, o100341.tot_lines_ext_i_s_avg_cst,
0
The "discotw_admin.fiscal_cal_by_wk.flyrweek (:fyrweek)" is the function I use to get the Last year week number nased on the parameter for this week number.
But the problem with this approach is it fires the Function every time a record is read by the query which makes the query to run long time.
Is there anyway I can use a subquery that fires the function only once and use the value of the function in the main query in Discoverer.
I did tried to create a custom folder for the Date functions and use it in the query so that the query references the field on the cusom folder. But still I do not see any improvement in the performance.
Thanks in advance
Jay

Hi Jay
Yes, calculating like this on every row will have a drag on performance.
Have you considered using one of the analytic functions LAG or LEAD? They are designed for this type of reporting.
If you have considered them and rejected them can you explain why.
Another possibility is to use a SUM analytic like this:
SUM(Selling Price SUM)
OVER(PARTITION BY Size,Product
ORDER BY TO_DATE("Year",'YYYY')
RANGE BETWEEN INTERVAL '1' YEAR PRECEDING
AND INTERVAL '1' YEAR PRECEDING )
The caveat here is that RANGE INTERVAL must be a YEAR and the ORDER BY must return a date!
Does this help?
Best wishes
Michael

Similar Messages

  • Help with Date function in sql query....

    My question I guess is really 2...I'm trying to use the date function as a comparison in my WHERE clause in my sql command.
    1. My date format is dd-MMM-yy eg. (01-Apr-06) ... my problem is the Apr is lower case where my field in the database is 01-APR-06 so when I compare 01-Apr-06 to 01-APR-06 is doesnt find any rows. Is there away that I can make the Apr all upper case so that it is APR.
    2. My second problem is getting this "date" field to work in my sql stmt I keep getting errors and it works fine if I take my attempts at trying to compare the date.
    --------------Date Code----------------------------------------------------------
    <%!
    String getFormattedDate(java.util.Date d)
    SimpleDateFormat simpleDate = new SimpleDateFormat("01-MMM-yy");
    return simpleDate.format(d);
    %>
    <%
    java.util.Date d = new java.util.Date();
    String dateString = getFormattedDate (d);
    %>
    ---------------------------Sql statment------------------------------------------
    ResultSet rset = stmt.executeQuery ("SELECT name " + " FROM table where rdate = '01-APR-06' order by name ");
    Currently Im just hard coding the date but I need to make it so it uses the date code...so....
    rdate should equal the date from the formatted date in upper case
    something like
    rdate = <%= dateString %>
    Thanks in advance for any ideas anyone may have...

    There are sql functions upper & lower.
    SELECT name  FROM table where upper(rdate) = '01-APR-06' order by name Or you could convert the date to a string, and use the toUpperCase & toLowerCase java.lang.String methods. It doesn't make much of a difference--do you want the java compiler to do the string conversion or the database?

  • How to create user function in Data Functions in Query Designer?

    Could someone tell me how to create user function in Data Functions in Query Designer?
    I mean function like "NDIV0" in Data Functions.
    SAP BW 3.x.
    Query Designer (SAP BW 3.x)

    Hi check the following URL, it gives how to add in Formulas in formula Builder, not in DataFunctions.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f095592f-42f7-2a10-6ab1-c836a559b48f
    Thanks
    Reddy

  • Question - Passing date to a function from a Query

    Hello,
    I have a function which looks like this
    CREATE OR REPLACE FUNCTION CAL_DATES_FNC
    (fp_fddate IN VARCHAR2,
    fp_task IN VARCHAR2
    RETURN VARCHAR2
    IS
    BEGIN
    IF TO_CHAR(TO_DATE(fp_fddate,'YYYYMMDD'),'DD-MON-YYYY') <= TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD'),60),'DD-MON-YYYY')
    THEN
    RETURN TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD') +21,6 * SUBSTR(fp_task,-2)) ,'DD-MON-YYYY');
    ELSIF TO_CHAR(TO_DATE(fp_fddate,'YYYYMMDD'),'DD-MON-YYYY') >= TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD'),72),'DD-MON-YYYY')
    THEN
    RETURN TO_CHAR(ADD_MONTHS(TO_DATE(fp_fddate,'YYYYMMDD') +21,12 * SUBSTR(fp_task,-2)) ,'DD-MON-YYYY');
    END IF;
    END;
    I am using this function in a query as given below to pass a date fp_fddate
    The problem I am having is that the function is executing only the first part of the IF construct it is not going into the second IF condition.
    Can some one please let me know where I could be going wrong.
    SELECT ABC.PT,
    ABC.INV,
    ABC.INVSITE,
    ABC.TASK TASK_NAME,MAX(XYZ.FPDATE) fpdate ,
    CAL_DATES_FNC(MAX(XYZ.FPDATE),ABC.CPTASK) "DATE1",
    TO_CHAR(TO_DATE(ABC.D_YR||ABC.D_MON||ABC.D_DAY,'YYYYMMDD'),'DD-MON-YYYY') "DATE2"
    FROM ABC,
    XYZ
    WHERE ABC.PT = XYZ.PT
    AND PATSTAT.PT = '61090'
    GROUP BY ABC.PT,ABC.INV,ABC.INVSITE,ABC.D_YR,ABC.D_MON,ABC.D_DAY,ABC.CPTASK
    Regards
    Fm

    Hi,
    IQ wrote:
    Thanks for your messages. I am sending the scripts for the tables and insert statements in this message. Hope this will help to recreate the scenario.Don't forget to post the output you want from that data, and an explanation of how you get that output from the given data.
    Some of my answers are as follows,
    1) I know that the function is not in a proper syntax and thats the reason I need to fix it to be able to perform well. All I want is to compare the dates for a 5 year period(60 months) and then return something . For a period greater than 6 years (72 months) it should return something else.What dates do you want to compare? I assume fp_fddate is one of them, but what about the other(s)?
    When does the 5-year period begin or end?
    When does the 6-year period begin or end?
    I understand the fucntion may return either of two values. Do you care what those two values are? If so, give examples.
    What if the date is in neither the 5-year nor the 6-year period? (A fucntion has to return something in all cases. It can return NULL, if that's what you want.)
    What if the argument can't be interpreted as a date?
    2) Regarding the string datatype for date columns I cannot change the database design as this is done by another team, I can however explain them the points mentioned here.
    Please find below the scripts When you say TEST_DATES, do you mean TEST_DATES1. or is there another table? Test before you post.
    CREATE TABLE TEST_DATES
    pt VARCHAR2(10 BYTE),
    inv VARCHAR2(10 BYTE),
    invsite VARCHAR2(10 BYTE),
    task_name VARCHAR2(20 BYTE),
    fpddate VARCHAR2(8 BYTE),
    DATE1 VARCHAR2(4000 BYTE),
    DATE2 VARCHAR2(17 BYTE)
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (61090,'XDUMMY1'     ,'R1111','UP01'     ,'19990714','04-FEB-2000',     '17-JAN-2000');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,     'XDUMMY1','R1111','UP02','19990714','04-AUG-2000','20-JUL-2000');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,     'XDUMMY1','R1111','UP03','19990714','04-FEB-2001','19-JAN-2001');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP04','19990714','04-AUG-2001','21-JUL-2001');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP05','19990714','04-FEB-2002','20-JAN-2002');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP06','19990714','04-AUG-2002','19-JUL-2002');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP07','19990714','04-FEB-2003','17-JAN-2003');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP08','19990714','04-AUG-2003','15-JUL-2003');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP09','19990714','04-FEB-2004','20-JAN-2004');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP10','19990714','04-AUG-2004','25-JUL-2004');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP11','19990714','04-FEB-2005','27-JAN-2005');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP12','19990714','04-AUG-2005','25-JUL-2005');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP13','19990714','04-FEB-2006','28-JAN-2006');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP14','19990714','04-AUG-2006','30-JUL-2006');
    insert into test_dates1(pt,inv,invsite,task_name,fpddate,date1,date2)
    values (
    61090,'XDUMMY1','R1111','UP15','19990714','04-FEB-2007','31-JAN-2007');
    /You said that sometimes the data contains values like 'NA'. Shouldn;t the sample data have an example or two of that?
    Once the data is populated in the table , use the following query
    select TASK_NAME,RCM_CAL_THEORETIC_DATES_FNC(MAX(fpddate),task_name) "DATE1"
    from test_dates1
    group by task_name When you say
    RCM_CAL_THEORETIC_DATES_FNC, do you mean the function you posted in your first message, which was called
    CAL_DATES_FNC, or is there another funciton?
    When I make those changes and run the query, I get 15 rows:
    TASK_NAME            DATE1
    UP06                 04-AUG-2002
    UP07                 04-FEB-2003
    UP14                 04-AUG-2006
    UP08                 04-AUG-2003
    UP10                 04-AUG-2004
    UP12                 04-AUG-2005
    UP15                 04-FEB-2007
    UP01                 04-FEB-2000
    UP02                 04-AUG-2000
    UP03                 04-FEB-2001
    UP05                 04-FEB-2002
    UP13                 04-FEB-2006
    UP04                 04-AUG-2001
    UP09                 04-FEB-2004
    UP11                 04-FEB-2005Is that correct?
    If so, what is the problem?
    If not, what results should I get?
    What is the function supposed to do?
    Edited by: Frank Kulash on Nov 9, 2010 4:45 PM

  • Pl/sql Year to Date Function

    Dear All!
    Its very urgent task for me. i'm working on Oracle discoverer. i'm creating Project Year to Date report. i need one year to date function. i've only period name. The scnerio is this, in our company financial year is starting from (April to March i.e 01-April-2011 to 31-mar-2012). i need to apply YTD function on Period name. when any user select any period it will show from 01-apr-2011 to select mont. for example if user select Feb-12 then it must be from 01-apr-2011 to 29-feb-2012.
    Please this is urgent.. give Query for function. please
    Regards
    Ahmed....

    Hello,
    Can you put an example on apex.oracle.com and provide a link, it will be much easier to help you out?
    Regards,
    Carl
    blog : http://carlback.blogspot.com/
    apex examples : http://apex.oracle.com/pls/otn/f?p=11933:5

  • Distinct function in Discoverer

    Is there a way to use a distinct function in discoverer on a text field? I have the below calculation which concatenates 4 fields.
    Point Of Sales His.Submitting Partner Number||' - '||Point Of Sales His.Cleansed Submit Partner Number||' - '||Point Of Sales His.Submitting Partner Name||' - '||Point Of Sales His.Cleansed Submit Partner Name
    without a distinct function the report pulls in well over a million records and cant be used in excel. The 4 fields i am pulling in contain information that is repeated hundreds of times over within the table, but i only want to see 1 record for each unique return. Each record contains additional information which make the entire record unique, but I am not interested in that information at this time.
    Any ideas?
    Thanks
    Chris

    Hi Chris
    If you have millions of rows of data then although Tamir's suggestion will work you might find that it takes a while to run.
    If your data does not have to be up to the minute I would consider creating a new table and populating it nightly with the data that you need. You can then use a SELECT DISTINCT query in a procedure and even index the column in question. This will make report performance must, much faster.
    Best wishes
    Michael

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Issue with running PL/SQL function returning Sql query

    hi, I am trying to create a report region by using the option of PL/SQL function returning sql query.
    I notice that it's very slow for the report region page to show up. In my PL/SQL function body, there are only 3 steps, first update all the 10 rows of varchar2 fields to null,then insert values to those fields, then select all from the table to show report results. It takes more than 5 minitues for the page to load up, how ever, if i run those steps in SQL*Plus, it only takes a couple of seconds to finish. Any suggestions?
    Thanks,
    gina

    Sergio, the codes are as followed,
    Declare
    q varchar2(32767); -- query
    Begin
    q := 'select "ID",'||
    '"ENTRY NAME","TOTAL","#CM","%CM","#CA",'||
    '"%CA", from Info_table';
    update info_table
    set "TOTAL" = '',
    "#CM" = '',
    "%CM" = '',
    "#CA" ='',
    "%CA"=''
    where "ID"<=10;
    // set all data in column Total to null,there is only 10 rows in the table
    update info_Table set Total = vTotal,
    "#CM" = vCM
    (those variables hold user key-in Text filed value)
    where ID = 1;
    return q;
    End;

  • Error in using aggregate function in Outer Query in Siebel Analytics

    Hi,
    When I am using aggregate function in outer query in Siebel Analytics I am facing error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59111] The SQL statement must include a GROUP BY clause. (HY000)
    Bellow is the code.
    SELECT test1.username saw_0, test1.desg saw_1,COUNT (test2.querydate) saw_2
    FROM (SELECT POSITION.CBL username,
    POSITION.CBP desg
    FROM "CM"
    WHERE (POSITION.BPTCD = 'Marketing')
    AND (POSITION.EDate =TIMESTAMP '1899-01-01 00:00:00'
    ) test1,
    (SELECT users.UN username,
    measures."Query Count" querycount,
    measures."Max Total Time" secs,
    topic.db dashboardname,
    "Query Time".DATE querydate
    FROM "Plan"
    WHERE (topic."Dashboard Name" IN ('DS'))) test2
    WHERE test2.username = LOWER (test1.username)
    AND test2.dashboardname = 'DS'
    GROUP BY test1.username, test1.desg

    Should your query be a valid SQL query?
    I can't think that the query you have would be valid in a SQL plus window.
    Chris

  • On Submit process not firing -report (PL/SQL function returning SQL query)

    Can anyone suggest possible causes / solutions for the following problem?
    I have a report region that uses a PL/SQL function returning SQL query. The report allows the user to update multiple fields / rows and then click a button to submit the page which should run the On-Submit process to update the database. However the process does not run and I get a 'HTTP404 page cannot be found' error; and when I navigate back using the Back button I cannot then navigate to any other page in my application without getting the same error. The button was created by a wizard selecting the options to submit the page and redirect to a (same) page. The button does not actually have a redirect in its definition but the wizard created a branch to the same page which should work and the button has the text 'submit as SUBMIT' next to it so it appears to be set up correctly.
    I have recreated this page several times in my application and I cannot get the On-Submit process to run. However I have created a cut down version of the same page in the sample application on apex.oracle.com at http://apex.oracle.com/pls/otn/f?p=4550:1:179951678764332 and this works perfectly so I am at a loss to understand why it does not work in my application. I cannot post any part of the application itself but if anybody would like to check out page 30 of the sample application (Customer Update Test tab) updating the surnames only, using credentials ja, demo, demo this is pretty much what I have got in my application.
    Any ideas would be much appreciated?

    Thanks for the suggestions guys. I have now identified that the problem goes away when I remove the second table from my report query. The original report query retrieved data from two tables and the process was updating only one of the tables. I thought I had approached the task logically i.e. first get the report to display the records from the two tables, then get the process to update the first table and finally to modify the process further to update the second table.
    Can anyone point me to an example of multiple row updates on multiple tables using a PL/SQL function returning an SQL query?

  • SQL Query ( PL/SQL function body returning query ) page

    Hello Friends,
    I have a page with type SQL Query ( PL/SQL function body returning query ).
    I have written a pl/sql block that returns a sql query - select statment.
    Some times i am getting no data found error - does it got to do with the variable that stores the query .
    =======================
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Error ERR-1101 Unable to process function body returning query.
    OK
    =====================
    When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
    Here's the pl/sql block ..
    The query is generated while the user is navigating through pages ..
    ====================
    declare
    l_return_stmt varchar2(32767);
    l_select varchar2(32000);
    l_from varchar2(32000);
    l_where varchar2(32000);
    l_order_by varchar2(32000);
    l_stmt_recordcount varchar2(32000);
    l_recordcount number ;
    begin
    l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
    ||:P10_VARLIST4||:P10_VARLIST5;
    l_from := ' from '||:P10_RELATION;
    if length(:P10_WHERE) > 0 then
    l_where := ' where '||:P10_WHERE;
    else
    l_where := '';
    end if;
    if length(:P10_ORDER_BY) > 0 then
    l_order_by := ' order by '||:P10_ORDER_BY;
    else
    l_order_by := '';
    end if;
    l_return_stmt := l_select||l_from||l_where||l_order_by;
    :P10_STMT := l_return_stmt;
    return l_return_stmt;
    end;
    =============================
    Appreciate your help in this regard.
    thanks/kumar
    Edited by: kumar73 on Apr 22, 2010 6:38 AM

    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?

  • Column order in SQL Query (PL/SQL function returning a query)

    Hi,
    when I define a PL/SQL function returning a query inside a region, I often find that the column order is arbitrarily changed.
    How do I enforce the column order ?
    Bye,
    Flavio

    I removed the 11th column called service_name from this dynamic query: and now the report says: report error:
    ORA-01403: no data found. I messed around with the Headiuns Type. It was set to Custom. I changed it to Column Names. There is no difference.
    I am not sure how to fix?
    declare topqry varchar2(32000);
    whereqry varchar2(32000);
    finalqry varchar2(32000);
    var_status varchar2(100);
    division_status varchar2(50);
    office_status varchar2(1000);
    user_status varchar2(1000);
    overdue_status varchar2(1000);
    begin
    if :P10_FALLBACK = 'All' then
    var_status:= ' and vp.status in (''FA'',''FBA'',''FBI'',''25%'',''50%'',''90%'',''Closed'') ';
    elsif :P10_FALLBACK = 'Active' then
    var_status:= ' and vp.status in (''FA'',''25%'',''50%'',''90%'',''FBA'') ';
    elsif :P10_FALLBACK = 'FB' then
    var_status:= ' and vp.status in (''FBA'',''FBI'') ';
    elsif :P10_FALLBACK = 'Closed' then
    var_status:= ' and vp.status in (''Closed'') ';
    elsif :P10_FALLBACK = 'Inactive' then
    var_status:= ' and vp.status in (''FBI'') ';
    end if;
    if :P10_DIVISION = 'All' then
    division_status:= ' and vp.vms_division in (''News'',''Ad Services'') ';
    elsif :P10_DIVISION = 'News' then
    division_status:= ' and vp.vms_division in (''News'') ';
    elsif :P10_DIVISION = 'Ad' then
    division_status:= ' and vp.vms_division in (''Ad Services'') ';
    end if;
    if :P10_OFFICE = '%' then
    office_status:= ' and OFFICE_ID in (select office
    from VMS_OFFICE_ACCESS
    where user_id = lower(:P0_user) ) ';
    else
    office_status:= ' and OFFICE_ID in :P10_OFFICE ';
    end if;
    if :P10_LIMIT_USER = '%' then
    user_status := ' and SALESPERSON in (select first_name || '' '' || last_name
    from VMS_PROSPECT_users u
    join vms_office_access o
    on u.office_id = OFFICE
    where o.user_id = lower(:P0_USER) ) ';
    else
    user_status:= ' and SALESPERSON in (:P10_LIMIT_USER ) ';
    end if;
    if :P10_SHOW_OVERDUE = 'Show' then
    overdue_status:= ' and target_close_date <= sysdate ';
    var_status:= ' and vp.status in (''25%'',''50%'',''90%'',''FBA'') ';
    else
    overdue_status:= ' and FIRST_APPOINTMENT between
    nvl(to_date(:P10_FIRST_APPT_START, ''mm/dd/yyyy''),FIRST_APPOINTMENT) and
    nvl(to_date(:P10_FIRST_APPT_END,''mm/dd/yyyy''),FIRST_APPOINTMENT) ';
    end if;
    topqry := 'SELECT OFFICE_ID ,vp.PROSPECT_ID ,ENTRY_DATE ,ACCOUNT , NEXT_CONTACT_DATE ,ACTION_STEP ,
    TARGET_CLOSE_DATE ,vp.STATUS ,SALESPERSON ,vp.SALES_TYPE ,service_name , FIRST_APPOINTMENT ,MODIFY_DATE ,EST_ANNUAL_REVENUE ,EST_INCREMENTAL_REVENUE ,
    pi.NOTES , pi.SALES_TYPE ,pi.STATUS ,Contact ,Origin_Source FROM VMS_PROSPECTING_ITEMS pi right outer join VMS_PROSPECTS vp on vp.PROSPECT_ID = pi.PROSPECT_ID left outer join VMS_SERVICES vs on vs.service_ID = pi.service_ID where 1 = 1 ';
    whereqry := ' and (not exists (select *
    from VMS_PROSPECTING_ITEMS i3
    where vp.prospect_id = i3.prospect_id)
    or exists (select *
    from VMS_PROSPECTING_ITEMS i2
    where i2.order_id = pi.order_id
    and active = ''Y'' )) and instr(upper(ACCOUNT),upper(nvl(:P10_ACCOUNT,ACCOUNT))) > 0 ';
    whereqry := whereqry || var_status || division_status || office_status || user_status || overdue_status;
    finalqry := topqry || whereqry;
    return finalqry ;
    end;

  • DATE function to get name of day for a Date given?

    hi guys,
    can anyone tell me what is the DATE function to get the name of day for a date given
    (12/dec/2004)---returns SUNDAY

    Hi peter
    Your Query will return an error.
    SQL> select to_char(to_date('12/dec/2004', 'mm/mon/yyyy'), 'DAY')from dual;
    select to_char(to_date('12/dec/2004', 'mm/mon/yyyy'), 'DAY')from dual
    ERROR at line 1:
    ORA-01816: month may only be specified once.
    month is specified twice.
    select to_char(to_date('12/dec/2004', 'dd/mon/yyyy'), 'DAY')from dual;
    Regards
    Sasidhar.P

  • Validating Date parameter in discoverer

    Hi
    In the discoverer is it possible to validate or restrict the users to enter the wrong format of the date e.g. if the date format to be entered is dd-mm-yyyy, the system should not allow the users to enter mm-dd-yy,
    Is it possible to put any validation?
    As of now what is happening is discoverer is not telling me any thing after running for few minutes i am not getting any result, after that if i check i found that the date is in the wrong format
    Regards
    Ramesh Kumar S

    Hi
    If I may throw an aside in here. If your users are using 10.1.2 Plus there should be no need for users to key anything into any date parameter because Discoverer now has a calendar for this use. I find it much easier to teach my users to use a calendar than to try and teach them how to key dates in correctly.
    One other thing you might want to consider if you have not already done so is to standardize a date format across your entire Discoverer installation. Then the date format will be obvious because its the same one they see all of the time.
    Nevertheless, if you still want a mechanism to trap what users are keying it is possible to create functions that trap formats displaying appropriate error messages.
    Best wishes
    Michael

  • Passing parameter into select statement by using function in discoverer

    I have created two functions in database named Period_in and Period_out and a global variable  g_period_name
    I have called Period_out function in VIEW(Select statement where condition).
    I have registered Period_in function in discoverer admin then created calculation (called Period_in(:input parameter))in discoverer plus.
    My expectation is user will enter period name and that will hit Period_in function and returns 1 and stores entered period name in g_period_name at runtime. then VIEW will executed and fetches data.
    But i am getting no data found.
    Problem is 2 functions running at the same time in select statement. Please help me to overcome this. Thanks in advance
    FUNCTION period_in (p_period VARCHAR2)
          RETURN NUMBER
       AS
       BEGIN
          g_period_name := p_period;
          RETURN 1;
       END period_in;
       FUNCTION period_out
          RETURN VARCHAR2
       AS
       BEGIN
          RETURN g_period_name;
       END period_out;

    You can use this code: 
    WITH cte
    AS ( SELECT EmpID ,
    EmpName ,
    [dbo].[udf_testFunction](EmpID) AS testfunctionvalue
    FROM #Temp
    SELECT EmpID ,
    EmpName ,
    testfunctionvalue ,
    testfunctionvalue * EmpID ,
    testfunctionvalue + 2
    FROM cte
    But using scalar functions in select clause can hurt the performance. Please see this link: 
    SQL Server Scalar User Defined Function Performance
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

Maybe you are looking for

  • Fix for a very slow browser

    Hello All, I hope this helps. Here's my problem. My browser, when wireless, had slowed down dramatically. Loading pages took forever. I tried it at home and the office and both were slow. When I plugged it directly into the Ethernet it was blazingly

  • Console mode service pack install in 6.1

    Hi, I am trying to apply sp1 to WLS6.1 on solaris 2.8 in console mode java -cp wls61sp1_upgrade_generic.zip install -i console The above command goes through the choose locale step It then says press <enter> to continue. At the next point it should a

  • Unknown profile password

    I've won a macbook air in a coprorate competition expo by filling in their form at their expo booth, and after opening up the box (unsealed) I find that someone has already set up a profile on it and set a password! How can I access the computer now

  • PDK June now available

    PDK June is now available, you can view it at http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/INDEX.HTML

  • Adobe acrobat pro app will not start when I click

    Just used installer to download Acrobat Pro.  When I click on icon or click in applications file nothing happens