Pre query , post query where date = mon-yyyy

I have a tabular block B2 with many records
this block items are vouhcerno, voucherdate. voucherno number(6) and voucherdate date.
when new form instance i execute query it shows me all the records working fine.
I add one list item here when new form instance this list item got record like
Jan-2009
Feb-2009
Mar-2009
so on...
I want that when i select Jan-2009 from list item and press button
block B2 only show my January 2009 records.
I tried to this in pre query and also post query trigger but not successful.
Kindly guide me .

Arun really tnx, you are helping me.
I m sorry Your this code also not working.
i want to add one more condition in this code
SET_BLOCK_PROPERTY('b2',DEFAULT_WHERE, 'to_char(voucherdate,''fmmon-fmYyyy'')= ''' || Lower(:vdate ) || ''''  );
And :vtype = "PV'
{code}
I m using this
{code}
SET_BLOCK_PROPERTY('b2',DEFAULT_WHERE, 'to_char(voucherdate,''fmmon-fmYyyy'')= ''' || Lower(:vdate ) || 'and :B2.vtype = PV'|| ''''  );
{code}
but Not return query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Working on Pre-query

    Hi Gurus,
    While using a pre-query,can data of more than one field be passed from control-query to display-query?
    How can we do that?
    Thanks in advance
    Walker

    A prequery is usually used to send back filter values to another query based on comples selection conditions - I am not sure if a prequery can return multiple fields - even if it did - the replacement path variable is attached to a characteristic and in that case only the relevant characteristic should get passed on.
    Arun

  • Query records using a date DD-MON-YYYY in Forms 6i and 10g

    In Forms 6i, I can query records by entering >20-dec-2006 in a date field which has length of 12 with a date format mask DD-MON-YYYY in date item property. Once this form is converted to 10g, I can only enter >2-dec-2006 for querying. If trying to enter the >20-dec-2006, then, it becomes >20-dec-200 and have no record found. Although I have the date length increased to 20, the result stays the same: can't enter 2 digits for day.
    Thanks for your help in advance.

    Appreciate your help. The date field has a format mask of DD-MON-YYYY. By entering >2-dec-2005 it will automatically be displayed as >2-DEC-2005 in Forms 6i or 10g. Also, the query property has case insensitive checked as Yes. The problem is with 10g, I can not enter anything at the 12th position. I can enter the date up to the 11th position >20-dec-200. In Forms 6i, this is not a problem. Thanks.

  • WHERE DATE QUERY Problem. Need Help.

    Hi, I have a problem doing a query on the clause where. I want to filter all the data on my table with a date filtering, I just want to show all the data with Date bigger than where specification.
    This is what I do.
    Select * from Table where DateLocal>'2007/01/01'
    But it shows and error: ORA-01861: literal does not match format string
    On my table the DateLocal is on this way: dd/mm/yyyy HH24:MI:SS, why I can't filtering by this date format yyyy/mm/dd???
    The fact is my application works with mysql too, and I don't want to broke this sintax. Select * from Table where DateLocal>yyyy/mm/dd
    What could I do??
    Thanks.

    Thanks that was one of my possibilities but the fact is I don't want to change all the code on my applicacion and make a case of for each data base, remember I can connect through the same application to oracle or mysql.
    I think there is not more solutions.
    Thanks anyway!

  • Querying a date column

    hi
    need help for a simple query. while quering a date column in forms6i. i am not able to retrive the data for that particular date.
    details:
    Data Type = Date
    Format Mask = DD-MON-YYYY HH24:MI:SS
    Max Length = 20
    when i enter the date (21-JUL-2008), the time comes by default as 00:00:00. I am able to query with a date value Eg: '01-JAN-2008 00:00:00' for which it retives. i presume it is taking the time as 00:00:00 for all dates. i need to retive all the details for that particular date for all time. how should i handle this?
    Thanks in advance

    If you have an entry in the date field when you execute the query then the records retrieved will have to match that field. This is often unsuitable for datetime fields so you can do this to get round it:
    Create a new datetime* item in a control block.
    Include the new item in the main block's where clause property:
    (trunc(date_column) = :control.date_item or :control.date_item is null)Add code to the main block's pre-query trigger to set the new item and the item in the main block:
    if trunc(:block.date_column) = :block.date_column then
         ::control.date_item := :block.date_column;
         :block.date_column := null;
    else
         ::control.date_item := null;
    end if;Now when the user enters a date and time the form will retrieve records which match exactly, but when they enter just a date (or they enter the time as midnight) the form will fetch all records for that day.
    You could also use forms' default Query/Where functionality but this is more difficult for end users and is a potential security issue
    http://www.red-database-security.com/wp/sql_injection_forms_us.pdf
    *I use forms 9.0.4 and date items are ok with time components but after Rosario's post I'll assume you need a datetime in 6i.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Is it possible to display a date as (DD-MON-YYYY) in excel output using excel template in xml publisher

    Is it possible to display a date as (DD-MON-YYYY) in excel output using excel template in xml publisher where date should be displayed as date only not string.

    I've tried to use hierarchy node variables, but it seems like you can't specify a attribute of the hierarchy such as level.  So with the WBS hierarchy, if you create a hierarchy node variable, you specify the WBS value to select (If I understand this correctly).  I wish I could instead specify "give me all the WBS nodes that happen to have the value of the level attribute greater or equal to 3.  If I understand Juergens post, he is saying make security access so that only certain WBS levels can be returned in the query.  I suppose we can try that, but that would then preclude getting the level 1 and 2 in the future if the authorization is global.

  • Report from sql query invalid date condition

    Hi, I created a Reports From SQL Query. My sql is like
    "select column1, column2
    from myschema.tablename
    where mydate > :p_date1 and mydate < :p_date2"
    I am using portal with turkish and english option. If I pass p_date paramaters 'dd-MON-yyyy' format
    (for example p_date1 = 23-MAR-2003 p_date2 = 26-APR-2003) in english mode portlet is return correct result,
    in turkish mode 'No Row Returned'. I changed my sql statement with
    "select column1, column2
    from myschema.tablename
    where to_date(mydate,'dd/mm/yyy') > to_date(:p_date1,'dd/mm/yyy') and to_date(mydate) < to_date(:p_date2,'dd/mm/yyyy')"
    and I pass p_date parameters 'dd/mm/yyyy' format (for example p_date1 = 23/03/2003 p_date2 = 26/04/2003)
    but now turkish and english mode No row returned.
    How may I write correct sql statament. My database NLS_DATE_FORMAT=DD/MM/YYYY and NLS_LANGUAGE=TURKISH.
    thanks.

    Hi,
    Try this for turkish mode:
    Case 1: the 'mydate' column has a kind of a char data type (like char, varchar or varchar2)
    and a value like '30/03/2003'
    "select column1, column2
    from myschema.tablename
    where
    to_date(mydate,'DD/MM/YYYY') > :p_date1
    and
    to_date(mydate,'DD/MM/YYYY') < :p_date2"
    Case 2: the mydate column has a date type:
    "select column1, column2
    from myschema.tablename
    where
    mydate > :p_date1
    and
    mydate < :p_date2"
    In both cases use the following parameter values:
    p_date1 = 23/03/2003
    p_date2 = 26/04/2003
    This should work
    Thanks
    Peter

  • I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me..

    I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
    here is the procedure
    create or replace
    procedure temp(
        P_MTR_ID VARCHAR2,
        P_FROM_DATE    IN DATE ,
        P_THROUGH_DATE IN DATE ) AS
        L_XML CLOB;
        l_query VARCHAR2(2000);
    BEGIN
    l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
       ' AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ',''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
        ' AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ','' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
    SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML   FROM DUAL;
    INSERT INTO NK VALUES (L_XML);
    DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
    END;
    OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
    L_QUERY IS :SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '1'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '2'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)

    The correct way to handle this is to use bind variables.
    And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
    create or replace procedure temp (
      p_mtr_id       in varchar2
    , p_from_date    in date
    , p_through_date in date
    is
      l_xml   CLOB;
      l_query VARCHAR2(2000);
      l_ctx   dbms_xmlgen.ctxHandle;
    begin
      l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
      l_ctx := dbms_xmlgen.newContext(l_query);
      dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
      dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
      dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
      l_xml := dbms_xmlgen.getXML(l_ctx);
      dbms_xmlgen.closeContext(l_ctx);
      insert into nk values (l_xml);
    end;

  • How to convert date  into dd mon yyyy format

    hi all,
    i have a problem in date format i am using date like below .
    <%java.util.Date date = new java.util.Date();%>
    i am inserting date into a table and its storing like this
    insert into tablename (d_date) values (date)
    and its inserting date like below
    Sun Oct 19 09:05:45 GMT+03:00 2003
    i want to fetch date in dd mon yyyy format.
    with this format i want to make a select query.i struck with the format conversion.
    how to do this.
    any comments please.
    any help

    hi all,
    i understand now where i am wrong.
    the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
    i executed the same code in a different server where date and time jones are english its working fine.
    All the problem is in regional setting and not the jsp code.
    <%
    String whtEverDateFormatYouWAnt = "dd MMM yy";
    String str = new SimpleDateFormat(whtEverDateFormatYouWAnt).format(new SimpleDateFormat("EEE MMM dd HH:mm:ss vvv yyyy").parse("Sun Oct 19 09:05:45 GMT+03:00 2003"));
    out.print(str);
    %>
    Thanks a lot for the excellent solution.
    Thanks again.

  • SQL Query on Date Range

    Hi, I am using Oracle 10g. I want a query which gives me below output.
    Data Setup
    ========
    create table t_date_range (
    ID     number (2),
    start_date     date,
    end_date     date);
    insert into t_date_range values (1,to_date('20110101', 'YYYYMMDD'),to_date('20110331', 'YYYYMMDD'));
    insert into t_date_range values (2,to_date('20110401', 'YYYYMMDD'),to_date('20110531', 'YYYYMMDD'));
    insert into t_date_range values (3,to_date('20110701', 'YYYYMMDD'),to_date('20110731', 'YYYYMMDD'));
    insert into t_date_range values (4,to_date('20110901', 'YYYYMMDD'),to_date('20111130', 'YYYYMMDD'));
    insert into t_date_range values (5,to_date('20111201', 'YYYYMMDD'),to_date('20111231', 'YYYYMMDD'));
    commit;
    SQL> select ID, to_char(start_date,'DD-MON-YYYY') START_DATE, to_char(end_date,'DD-MON-YYYY') END_DATE from t_date_range;
    ID START_DATE END_DATE
    1 01-JAN-2011 31-MAR-2011
    2 01-APR-2011 31-MAY-2011
    3 01-JUL-2011 31-JUL-2011
    4 01-SEP-2011 25-OCT-2011
    5 26-OCT-2011 30-NOV-2011
    6 01-DEC-2011 31-DEC-2011
    6 rows selected.
    I want result in this form:
    START_DATE END_DATE
    01-JAN-2011 31-MAY-2011
    01-JUL-2011 31-JUL-2011
    01-SEP-2011 31-DEC-2011
    Means if there is a difference of exact one day between "start_date of 2nd row" and "end_date of first row" then make a single row as shows in above results set.
    Thanks!

    Hi,
    Solomon Yakobson wrote:
    Keep in mind, Franks's solution assumes date ranges do not overlap. ...That's true. If rows can overlap, then we might need to use two sub-queries, like you did: one to see if a new group starts with this row, and another to count how many new groups have already started.
    The solution you posted assumes a relationship between id and dates. If we add a row like this to the sample data:
    insert into t_date_range values (6,to_date('20101201', 'YYYYMMDD'),to_date('20121231', 'YYYYMMDD'));that overlaps all the others, then how would that solution work?
    LAG won't work, because no matter how we sort the rows, we can't be sure that overlapping rows will be consecutive.
    Here's one way to handle overlapping rows:
    WITH     got_new_grp          AS
         SELECT     id, start_date, end_date
         ,     CASE
                  WHEN  start_date > 1 + MAX (end_date) OVER ( ORDER BY  start_date
                                                                        ,             id
                                                                        ROWS BETWEEN  UNBOUNDED PRECEDING
                                                  AND      1      PRECEDING
                  THEN  1
              END     AS new_grp
         FROM     t_date_range
    ,     got_grp          AS
         SELECT  start_date, end_date
         ,     COUNT (new_grp) OVER ( ORDER BY  start_date
                                     ,           id
                             ) AS grp
         FROM    got_new_grp
    SELECT       MIN (start_date)     AS start_date
    ,       MAX (end_date)     AS end_date
    FROM       got_grp
    GROUP BY  grp
    ORDER BY  start_date
    ;This solution uses id (assumed to be unique) just to get a consistent ordering, in case 2 (or more) rows have exactly the same start_date. It does not assume any relationship between ids and either start_date or end_date.
    I'm also assuming that start_date<=end_date on each row.
    Edited by: Frank Kulash on May 11, 2011 12:54 PM
    The above refers to the solution you oriognally posted, which was:
    with t1 as (
                select  id,
                        start_date,
                        end_date,
                        case
                          when lag(end_date) over(order by id) + 1 >= start_date then 0
                          else 1
                        end start_of_group
                  from  t_date_range
         t2 as (
                select  id,
                        start_date,
                        end_date,
                        sum(start_of_group) over(order by id) grp
                  from  t1
    select  min(start_date) start_date,
            max(end_date) end_date
      from  t2
      group by grp
      order by grp
    ;

  • SQL Query - Max Date - Group By

    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of records
    SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
    TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
    SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
    SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
    SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
    SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
    SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
    SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
    SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
    SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
    SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
    SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
    SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
    SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
    SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM FACT_RESULT_VW a,
    PLAN_VW b,
    SUB_VW c ,
    CUST_VW d,
    FACT_TRANS e,
    WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )+
    AND a.PP_KEY = b.PP_key
    AND a.ID = c.ID
    AND c.CUST_ID = d.CUST_ID
    AND c.ID = E.ID
    AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND a.DATE_KEY = 20100601
    AND A.PEF_ID = 1
    GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
         TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')

    Hi,
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Simplify the problem as much as possible.
    Would you have the same problem if only two tables, fact_result_vw and fact_trans, were involved? Then post a question involving only those two tables. Once you have a solution for the simplified problem, adding the other tables will be easy.
    Would the problem be essentially the same if you were pivoting only 2 or 3 columns, instead of 13? Then post a question where you're only pivoting 2 or 3 columns. Once you have a solution, adding the others will be easy.
    787771 wrote:
    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of recordsDo you want only the latest transaction from the fact_trans table, or the latest transaction for each customer ?
    What if there's a tie, and the same customer has two (or more) transactions at the same date, and none later?
    Since you're not using any of the data from the fact_trans table, the effect is just to eliminate customers who are not in fact_trans. You can do that more simply with an IN or EXISTS sub-query.
    If you really do need something from the fact_trans table in the main table, then one way you can get the results you want is to use the analytic RANK (or ROW_NUMBER) function to number the rows in fact_trans by trans_date (latest first), with a separate set of numbers (1, 2, 3, ...) for each customer, like this:
    WITH     fact_trans_1     AS
         SELECT     id     -- all columns that you need
         ,     RANK () OVER ( PARTITION BY  id
                          ORDER BY          date_trans     DESC
                        )     AS r_num
         FROM     fact_trans
    SELECT        TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
           SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
           SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
           SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
           SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
           SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
           SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
           SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
           SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
           SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
           SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
           SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
           SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
           SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM        FACT_RESULT_VW      a,
           PLAN_VW           b,
           SUB_VW           c,
           CUST_VW           d,
           FACT_TRANS_1          e,
    WHERE        e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )
    AND       e.r_num     = 1
    AND        a.PP_KEY      = b.PP_key
    AND        a.ID           = c.ID
    AND       c.CUST_ID      = d.CUST_ID
    AND       c.ID           = E.ID
    AND       c.DATE_JOIN       >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       c.DATE_JOIN      <  To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       a.DATE_KEY = 20100601
    AND       A.PEF_ID = 1
    GROUP BY  TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')I hope this answers your question.
    If not, post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.

  • Query with date

    Hi,
    The query has the following output which is built by multiple tables :
    Cust No. Invoice Date Balance
    1 01-jan-06 100
    1 10-mar-06 200
    1 20-mar-06 50 ----->
    2 15-jan-06 25
    2 02-mar-06 50
    2 10-mar-06 100 ----->
    Suppose if I enter the invoice date as 'MAR-06' I should get the output of two records only indicated by arrow....
    1 20-mar-06 50 ----->
    2 10-mar-06 100 ----->
    Please let me know to frame the query.
    Thanks....

    in your query you need to add
    where TO_CHAR(TRUNC( Inoice_date, 'MONTH'), 'MON-YYYY' ) = 'MAR-2006'
    By the way, you have one more mar-2006 row well two more
    Cust No. Invoice Date Balance
    1 01-jan-06 100
    1 10-mar-06 200 ------>here
    1 20-mar-06 50 ----->
    2 15-jan-06 25
    2 02-mar-06 50 -----> and here
    2 10-mar-06 100 ----->

  • Querying a date field with different masks in form and database

    Dear friends,
    I have a field with date format mask dd/mm/yyyy hh24:mi:ss, but the same field has date format dd/mm/yyyy inside the form which queries it.
    If I run this form, obviously I will query this date in dd/mm/yyyy format mask, but this date is not being found because it doesn't include hh24:mi:ss (hour) from the database field.
    How can I solve this problem? I tried to change my form, putting a format mask with hours, but it requires me to query this date with time, and obviously no one needs to know the exact moment (with seconds!) when the date was recorded in the database.
    Thanks, and best regards,
    Franklin

    Franklin,
    You could instruct your users to use the '%' when they enter a date search criteria. Another alternative would be to programatically add the '%' to the date. Also, if your Block based on a view you could alter the vuew to use TRUNC() on the date field to drop the time.
    Another option would be to use the Pre-Query trigger to modify the Block WHERE clause to: TRUNC(date_field) = :block.date_field.
    Hope this helps.
    Craig...
    -- If my response or the response of another is helpful or answers your question, please mark the response accordingly. Thanks!

  • Trouble With Query Between Dates:

    Hello Again,
    The query below is giving some trouble in that the line where 'CURRENT_DATE' is between 'START_DATE' and 'END_DATE.
    The query returns records close to those dates but some missing on the END_DATE. I was wondering if there is 'time at play here? How is only the date component used for the search?
    select * from (
    SELECT TO_CHAR (LEAVE.START_DATE, 'DD-MON-YY') AS Start_Date,
    TO_CHAR (LEAVE.END_DATE, 'DD-MON-YY') AS end_date,
    TO_CHAR (CURRENT_DATE, 'DD-MON-YY')AS CURRENT_DATE,
    LEAVE.NAME as NAME,
    LEAVE.ID as ID,
    LEAVE.DAYS as Days,
    LEAVE.SUPERVISOR as Supervisor,
    LEAVE.LEAVE_TYPE,
    FROM "LEAVE"
    WHERE CURRENT_DATE BETWEEN start_date AND end_date
    Kind Regards,
    Steve Welch

    Hi Steve,
    You should be aware that the Oracle datatype DATE also includes a time component.
    select to_char(current_date,'DD-MON-YYYY HH24:MI:SS') date_and_time from dual;
    DATE_AND_TIME       
    18-AUG-2011 13:29:49 Could it be that you are missing some records because they have a time which falls outside your condition?
    Regards
    Andre

  • Join with another table in pre-query

    Hi,
    We have a large data block and we need to order some columns based on street name for example, not id. The base table of db block contains an id_street column, and 'streets' table contains id and name.
    Ok, in pre-query trigger of that block, we have a complex logic and we dynamically build the where clause. At the end, we set the order_By clause of the block, to order the rows, for example we need to order by the 'my_date' column asc (it's a date type column), and street desc; but street NAME, not id. We don't want to use a from clause query, because the dynamically where clause logic it's complex.
    How can we join the db block table with 'streets' table in pre-query, so when constructing the order by clause to specify something like
    set_block_property('ADRESE_NEZONATE', order_by, 'my_date, name desc');where 'name' is the name of the street, from the 'streets' table.
    Is it possible in pre-query, somehow? Or, in my case where can I join with that table and use that column in pre-query at setting order by?
    Thanks!
    Edited by: Roger25 on 26.04.2013 12:31

    I understand what you say but partially.. please explain in more detail how to do that;
    How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
    Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
    Thanks.

Maybe you are looking for