Query with scalar valued function with date filter

Hello experts
i have a problem by filtering my results with the date
i have written the following code
SELECT
T1.ItemCode
, T1.Dscription
,DBO.F_CALCULATION_QUANTITY(T1.ITEMCODE)
FROM OINV T0 
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
WHERE
(T0.DOCDATE BETWEEN '2010-11-01' AND '2010-11-30')
and (t2.cardcode ='80022')
and (T0.CANCELED= 'N')
group by  t1.itemcode, T1.Dscription, t2.suppcatnum
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
(@ITEMCODE AS NVARCHAR(10))
RETURNS
NUMERIC(19,2)
AS
BEGIN
DECLARE
@RESULT1 AS NUMERIC(19,2),
@RESULT2 AS NUMERIC(19,2),
@RESULT AS NUMERIC(19,2)
SELECT @RESULT1=SUM(A.QUANTITY)
FROM INV1 A
JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN  '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
SELECT @RESULT2=SUM(A.QUANTITY)
FROM RIN1 A
JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
--SELECT @RESULT=@RESULT1- @RESULT2
RETURN @RESULT
END
the problem i have is that i want to filter my results accoring to the date provided by the user. i want it to be dynamic query.
by now, what i do is to edit the docdate in the function in order to get the desired results. this is not what i want.
could you please help me on this way in order to let the user to input the date?if i add the [%] in the query, it does not bring me the right results

i have already edited the function to
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
(@ITEMCODE AS NVARCHAR(10),
@STARTDATE1 as DATETIME,
@ENDDATE1 AS DATETIME
RETURNS
NUMERIC(19,2)
AS
BEGIN
DECLARE
@RESULT1 AS NUMERIC(19,2),
@RESULT2 AS NUMERIC(19,2),
@RESULT AS NUMERIC(19,2)
SELECT @RESULT1=SUM(A.QUANTITY)
FROM INV1 A
JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
SELECT @RESULT2=SUM(A.QUANTITY)
FROM RIN1 A
JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
RETURN @RESULT
END
could you please how to edit the query as well?
i have added the following code and it comes up with the right itemcode but the quantity does not work
DECLARE
@ITEMCODE AS NVARCHAR(10),
@STARTDATE1 as DATETIME,
@ENDDATE1 AS DATETIME
SET @STARTDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-01')
set @ENDDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-30')
SELECT
T1.ItemCode
, T1.Dscription
,DBO.F_CALCULATION_QUANTITY(@ITEMCODE,@STARTDATE1,@ENDDATE1)
FROM OINV T0 
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
WHERE
(T0.DOCDATE BETWEEN @STARTDATE1 AND @ENDDATE1)
and  (t2.cardcode ='80022')
and (T0.CANCELED= 'N')
group by  t1.itemcode, T1.Dscription, t2.suppcatnum
the result is this
70200     alert1     0.00
70210     alert2     0.00
70220     alert3     0.00
70230     alert4     0.00
as you can see the quantity is 0 and it shouldnt be
Edited by: Fasolis Vasilios on Oct 31, 2011 10:49 AM

Similar Messages

  • Create prompt with date-filter and initialize it with current date

    Oracle BI 11 g
    Hi!
    I need to create dashboard prompt with date-filter and initialize it with current date. How can I do that?
    I tried to create repository initialization block and add variable. But I don't know what should I write to DataSource? I tried to use functions Now(), Current_Date, sysdate (for example, SELECT Now() FROM tbl_Calendar) but without results - when I pressed "Test..." button I got errors - something like "Now() is unknown function" or "Incorrect syntax near key word Current_Date".
    After that I tied to use Presentation Variable in Prompt, but also without success ((
    Please, help me.

    I've created Repository Variable "CurrentDate", using SQL-query like this "select convert(varchar(10), getdate(), 104)" and now this variable is being initialized by value "07.04.2011". But I don't understand how to use this varible in DashboardPrompt! What item in list "Default selection" I should choose - "Variable Expression", "Server Variable" or something else? When I chose "Variable Expression" and write "CurrentDate" I got just string "CurrentDate" when preview Prompt. @{CurrentDate} gave me the same result.

  • How to compare result from sql query with data writen in html input tag?

    how to compare result
    from sql query with data
    writen in html input tag?
    I need to compare
    user and password in html form
    with all user and password in database
    how to do this?
    or put the resulr from sql query
    in array
    please help me?

    Hi dejani
    first get the user name and password enter by the user
    using
    String sUsername=request.getParameter("name of the textfield");
    String sPassword=request.getParameter("name of the textfield");
    after executeQuery() statement
    int exist=0;
    while(rs.next())
    String sUserId= rs.getString("username");
    String sPass_wd= rs.getString("password");
    if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
    exist=1;
    if(exist==1)
    out.println("user exist");
    else
    out.println("not exist");

  • Doubt querying with dates

    Hi all,i have a doubt querying an sql statement which involves date.
      1  SELECT rsh.shipment_num "File#"
      2        ,mmt.transaction_date "Transaction Date"
      3  FROM rcv_shipment_headers rsh,
      4       ap_suppliers aps,
      5    po_headers_all pha,
      6    po_lines_all pla,
      7    mtl_system_items_kfv msi,
      8    rcv_shipment_lines rsl,
      9    rcv_transactions rcv,
    10    mtl_material_transactions mmt,
    11    mtl_transaction_types mtt
    12  WHERE rsh.vendor_id = aps.vendor_id
    13  AND pha.po_header_id = pla.po_header_id
    14  AND pla.item_id = msi.inventory_item_id
    15  AND pha.po_header_id = rsl.po_header_id
    16  and pla.po_line_id = rsl.po_line_id
    17  AND rsl.shipment_header_id = rsh.shipment_header_id
    18  AND rsl.item_id = msi.inventory_item_id
    19  AND rsl.to_organization_id = msi.organization_id
    20  AND rcv.shipment_header_id = rsh.shipment_header_id
    21  AND rcv.organization_id = msi.organization_id
    22  AND rcv.po_header_id = pha.po_header_id
    23  AND rcv.po_line_id = pla.po_line_id
    24  --and pla.org_id = msi.organization_id
    25  AND rsh.SHIPMENT_NUM = 'AP1005'
    26  --AND mmt.transaction_date = TO_CHAR(TO_DATE('14-SEP-2012','DD-MON-YYYY'))
    27  AND rcv.transaction_type = 'DELIVER'
    28  AND rcv.source_document_code = 'PO'
    29  --AND rcv.subinventory = 'Vessel'
    30  AND mmt.rcv_transaction_id = rcv.transaction_id
    31  AND mmt.transaction_type_id = mtt.transaction_type_id
    32* AND rcv.organization_id = 81
    SQL> /
    File#                          Transacti
    AP1005                         14-SEP-12
    AP1005                         14-SEP-12Now passing date
      1  SELECT rsh.shipment_num "File#"
      2        ,mmt.transaction_date "Transaction Date"
      3  FROM rcv_shipment_headers rsh,
      4       ap_suppliers aps,
      5    po_headers_all pha,
      6    po_lines_all pla,
      7    mtl_system_items_kfv msi,
      8    rcv_shipment_lines rsl,
      9    rcv_transactions rcv,
    10    mtl_material_transactions mmt,
    11    mtl_transaction_types mtt
    12  WHERE rsh.vendor_id = aps.vendor_id
    13  AND pha.po_header_id = pla.po_header_id
    14  AND pla.item_id = msi.inventory_item_id
    15  AND pha.po_header_id = rsl.po_header_id
    16  and pla.po_line_id = rsl.po_line_id
    17  AND rsl.shipment_header_id = rsh.shipment_header_id
    18  AND rsl.item_id = msi.inventory_item_id
    19  AND rsl.to_organization_id = msi.organization_id
    20  AND rcv.shipment_header_id = rsh.shipment_header_id
    21  AND rcv.organization_id = msi.organization_id
    22  AND rcv.po_header_id = pha.po_header_id
    23  AND rcv.po_line_id = pla.po_line_id
    24  --and pla.org_id = msi.organization_id
    25  --AND rsh.SHIPMENT_NUM = 'AP1005'
    26  AND mmt.transaction_date = TO_CHAR(TO_DATE('14-SEP-2012','DD-MON-YYYY'))
    27  AND rcv.transaction_type = 'DELIVER'
    28  AND rcv.source_document_code = 'PO'
    29  --AND rcv.subinventory = 'Vessel'
    30  AND mmt.rcv_transaction_id = rcv.transaction_id
    31  AND mmt.transaction_type_id = mtt.transaction_type_id
    32* AND rcv.organization_id = 81
    SQL> /
    no rows selectedCan anyone pls suggest me where i am doing wrong.
    Any help is appreciated,
    Thanks in advance

    You have already got your answer.
    >
    yes works out,thanks very much.May i know the reason why it didn't worked out earlier?
    Thanks
    >
    Hope, the below example will make things more clear to you.
    SQL> CREATE TABLE m003 AS
      2    (SELECT 1                                                       id,
      3            To_date('14/09/2012 23:00:00', 'dd/mm/yyyy hh24:mi:ss') dt
      4     FROM   dual
      5     UNION ALL
      6     SELECT 2,
      7            To_date('14/09/2012 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
      8     FROM   dual
      9     UNION ALL
    10     SELECT 3,
    11            To_date('14/09/2012 01:00:00', 'dd/mm/yyyy hh24:mi:ss')
    12     FROM   dual
    13     UNION ALL
    14     SELECT 4,
    15            To_date('02/03/2012 23:00:00', 'dd/mm/yyyy hh24:mi:ss')
    16     FROM   dual);
    Table created.
    SQL> select * from m003;
            ID DT
             1 14-SEP-12
             2 14-SEP-12
             3 14-SEP-12
             4 02-MAR-12
    SQL> SELECT *
      2  FROM   m003
      3  WHERE  dt = To_char(To_date('14-SEP-2012', 'DD-MON-YYYY'));
            ID DT                                                                  
             2 14-SEP-12   Here, 14-SEP-2012 is a string. You are converting a string to date to compare with a column data which is a date. It does not make sense to convert to string again!
    SQL> select to_char(TO_DATE('14-SEP-2012','DD-MON-YYYY'),'DD-MON-YYYY HH24:MI:SS
    ')  from dual;
    TO_CHAR(TO_DATE('14-
    14-SEP-2012 00:00:00As you can see, TO_DATE('14-SEP-2012','DD-MON-YYYY') returns 14-SEP-2012 00:00:00.
    SQL> select * from m003
      2  where dt= TO_DATE('14-SEP-2012','DD-MON-YYYY');
            ID DT                                                                  
             2 14-SEP-12   In the above sql, it searches for the data that matches with date 14-SEP-2012 00:00:00 and hence 1 row.
    if your objective is to get the records where date is 14-SEP-2012 irrespective of the time associated with it,then write..
    SQL> select * from m003
      2  where dt >= TO_DATE('14-SEP-2012','DD-MON-YYYY')
      3  and dt < TO_DATE('14-SEP-2012','DD-MON-YYYY')+1
      4  ;
            ID DT                                                                  
             1 14-SEP-12                                                           
             2 14-SEP-12                                                           
             3 14-SEP-12     Now, what is the problem in below sql
    SQL> select * from m003
      2  where trunc(dt)= TO_DATE('14-SEP-2012','DD-MON-YYYY');
            ID DT                                                                  
             1 14-SEP-12                                                           
             2 14-SEP-12                                                           
             3 14-SEP-12   The SQL above will return same result as above BUT..
    In this case you are truncating the time for all the rows (ie time associated with the date will be 00:00:00) applying function trunc() which would be a bit slower. Moreover,
    if there is any index on this column then use of function on the column will ignore the index (if it is not a function based index).
    Hope it helps.
    Regards
    Biju

  • Query with date in where clause

    hi,
    i have build a view with join conditions from 8 tables. the data from this view is more then 100,000
    when i run the query with different clause its work with some seconds. but when i put date column in where cluase it sleeps.
    eg..
    where unit_id = 4 and t_id = 's09' and vb like '%amb%'
    works fine.
    where unit_id = 4 and t_id = 's09' and vb like '%amb%' and date between dt1 and dt2
    now sleep
    please ......give me some suggestions

    hi i have done the explain plan
    the result is
    Operation Object
    SELECT STATEMENT ()
    NESTED LOOPS ()
    NESTED LOOPS ()
    HASH JOIN ()
    HASH JOIN ()
    TABLE ACCESS (FULL) PR_PO_MST
    TABLE ACCESS (FULL) PR_SUPPLIER
    TABLE ACCESS (FULL) PR_PO_DTL
    TABLE ACCESS (BY INDEX ROWID) INDENT_MST
    INDEX (RANGE SCAN) ST_IND_MST_IDX
    TABLE ACCESS (BY INDEX ROWID) ST_ITEM
    Operation Object
    INDEX (UNIQUE SCAN) PK_ST_ITEM
    now wot do do????

  • IDOC: Problem with data filter for IDOC extension field

    Hallo!
    I've created an idoc extension for the basic type DEBMAS06 that works fine. Now I want to use a data filter for one field ( company code ) of my segment. Every segment with a company code different from 100 should be filtered and not send to the other client. But what happend is that for all customers that have at least one company code different from 100, all segments including the one with cc 100 were deleted and a error "Segment ... does not exist for message type DEBMAS" appeared on the screen.
    Does anyone have any ideas about this problem?

    Not sure about changes to be made at the filtering options.
    An alternative would be sending the data to XI as it is and perform the mapping to remove the unnecessary segments.
    Disadvantage: Unnecessary processing of segment would be done at XI.
    Advantage: The integration logic would be completely handled by XI.
    Regards,
    Prateek

  • *Urgent* Query with dates

    Hi Gurus,
    I am having problem in developing such a query which has calculations with dates. The problem is:
    I have
    base date for example 26-feb-2006
    statring day: 4
    interval: 5
    input date: 15-mar-2006
    Now the problem is I want to get the results from the query which will start 26-feb-2006+4 which is 02-mar-2006 and calculate the interval which is 5 days from '02-mar-2006' and run it every 5 (interval) days
    02-mar-2006
    07-mar-2006
    12-mar-2006
    I hope I have cleared everything.
    Please let me know as soon as possible.
    Thanks in advance.
    Aqil

    Where is the base_date coming from?
    declare
    v_jobno number;
    dbms_job.submit(v_jobno, 'SCHEMA_NAME.sp_my_proc();',
    -- first time running I schedule for 11 pm staring in 4 days
                              trunc(sysdate+4)+23/24,
    -- here the interval
                              'trunc(sysdate+5)+23/24' );
    end;

  • Compare scalar value to dynamic data

    I am trying to compare a scalar number input in the front panel to a dynamic data set(from DAQ) and return a boolean true if the condition is met. How can I compare one value to each data point in the acquisition data set?

    You can use the Convert From Dynamic Data and convert to a 1D array. The comparsion functions work with an array as one input and a scalar as another. The output is a Boolean array - the results of each element in the array to the scalar. I think you can also use the Comparison Express VI but I have seldom used any of the Express functions so I'm not sure about that.

  • How to get list data to Excel to create chart with date filter?

    Hi all,
    I have to create chart from a custom list in o365 site. There is one column named "Due Date" in my list. I want only those records whose Due Date is today or gone, I mean Due Date <= Today.
    How can do it?
    I have tried following ways.
    I have tried with REST (OData Data Feed) but not able to use Today's date (I mean dynamic) as filter.
    I have tried by Export to Excel my view and it is working but if I am uploading my excel file to o365 and refreshing data connection, it is showing error and not working.
    NOTE : I cannot user Power BI features like Power Query we have not that licences.
    Thanks,
    Ritesh
    Ritesh Goswami

    Hi Ritesh
    Not sure if I understood you correctly but what about creating a calculated field which has an if condition like
    if([Due Date]<=today(), "past", "future"
    and then just filter the 'past' / 'future' column?
    Kind regards,
    https://www.sharepointbay.com

  • Oracle OCI: Problem in Query with Date field

    Client compiled with OCI: 10.2.0.4.0
    Server: Oracle9i Enterprise Edition Release 9.2.0.4.0
    The problematic query is:
    SELECT CODIGO FROM LOG WHERE TEL = :telnumber AND DATE_PROC = '05-JUL-08'Table description:
    SQL>describe LOG;
    TEL NOT NULL VARCHAR2(15)
    CODIGO NOT NULL VARCHAR2(20)
    DATE_PROC NOT NULL DATEAs simple as it might look, when executed directly on the server with SQLPlus, it returns a result, but when executed from the app that uses OCI, this query returns OCI_NO_DATA always. In the beginning, the date value was also a placeholder, but I found out that even giving a literal like '05-JUL-08' didn't work. I have tried the following:
    <ul>
    <li>I've tried the basics: querying the DB from the client does work. It's this one that gives me trouble</li>
    <li>The query: SELECT CODIGO FROM LOG WHERE TEL = :telnumber does work</li>
    <li>Executing: ALTER SESSION SET NLS_DATE_FORMAT="DD-MM-YYYY"; before the query in both the server and the client. Same result: server returns data, client OCI_NO_DATA</li>
    <li>Tried changing DATE_PROC format, combining this with the use of TO_DATE(). Same result.</li>
    <li>Searched, searched, searched. No answer</li>
    </ul>
    I'm a bit desperate to find an answer, would appreciate any help and can provide as many further details as needed. Thanks.
    Edited by: user12455729 on Jan 15, 2010 5:59 AM. -Formatting-

    Hi,
    I've recreated your table and populated with your data.
    I've run your select using OCILIB on a 10gR2 (client and server) and the codes runs fine and give expected results.
    So the problem must resides in your code.... (i don't think it can be a OCI bug)
    Here is the ocilib code :
    #include "ocilib.h"
    int main(void)
        OCI_Connection *cn;
        OCI_Statement *st;
        OCI_Resultset *rs;
        char msisdn[100] = "11223344";
        char datetime[100] = "";
        if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
            return EXIT_FAILURE;
        cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
        st = OCI_StatementCreate(cn);
        OCI_Prepare(st, "SELECT "
                        "  CODIGO_BANCO "
                        "FROM "
                        "  VTA_LOG "
                        "WHERE "
                        "  TELEFONO = :msisdn AND "
                        "  FECHA_PROCESO = TO_DATE(:datetime, 'YYYYMMDDHH24MISS')");
        OCI_BindString(st, "msisdn", msisdn, sizeof(msisdn)-1);
        OCI_BindString(st, "datetime", datetime, sizeof(datetime)-1);
        strcpy(datetime, "20080705162918");
        OCI_Execute(st); 
        rs = OCI_GetResultset(st);
        OCI_FetchNext(rs);
        printf("%s\n", OCI_GetString(rs, 1));
        strcpy(datetime, "20080705062918");
        OCI_Execute(st); 
        rs = OCI_GetResultset(st);
        OCI_FetchNext(rs);
        printf("%s\n", OCI_GetString(rs, 1));
        OCI_Cleanup();
        return EXIT_SUCCESS;
    }Output is :
    BancoOne
    BancoTwoi recreated your data with
    create table VTA_LOG
         TELEFONO          VARCHAR2(15) NOT NULL ,
         CODIGO_BANCO     VARCHAR2(20) NOT NULL ,
         FECHA_PROCESO     DATE NOT NULL
    insert into VTA_LOG values ('11223344', 'BancoOne',  to_date('20080705162918', 'YYYYMMDDHH24MISS'));
    insert into VTA_LOG values ('11223344', 'BancoTwo', to_date('20080705062918', 'YYYYMMDDHH24MISS'));
    commit;Regards,
    Vincent

  • Creating a Query with Data from 4 Tables.

    Hey guys. I'm having a small problem figuring out the best way for me to handle this query.
    I'm trying to make a query which outputs the amount of appointments a GP has furfilled, and the total amount allowed.
    I have 4 tables, for each I'm just gonna list the relevent columns:
    Appointment: ID, Patient_ID.
    Patient: ID, GP_ID.
    GP: ID, Trust_ID.
    Trust: ID, Quota.
    Appointment table has 400 entries (2 per patient atm).
    Patient table has 200 entries.
    GP Table has 30 entries (GP's can be assigned to more than one person) .
    Trust table has 6 entries.
    What I need to do is, look at the appointment table and get the number of times each patient has an appointment.
    Go through the patient table, and find out which GP the patient in the appointment belongs to.
    Add each occurance to the correct GP.
    Find out which Trust each GP belongs to, and add the total for each GP to the correct Trust.
    Check the quota in the Trust table, to see if the total is more than the allowed.
    I can't seem to think of an easy or simple way for me to do this. Can anyone help please? Many thanks.

    Hi,
    That sounds like a job for JOIN.
    To check the quotas against the total, use the SUM function; either the aggregate SUM or the analytic SUM, depending on your requirements.
    Sorry this answer is so vague, but that's the bes I can do with the information provided so far.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. In this case, between 2 and 10 rows of data per table should be enough to show what you need to do.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.

  • Interactive Report with Date Filter

    Hi out there,
    I created an interactive report which contains a date column. The default filter-options just work fine. But my users need to filter with the data which is contained in the report e.g. if a row contains 21.06.2000 they want to see this value in the filter-list of this date column and not the predefined defaults (last five years, last day and so on).
    I already tried to specify the date as a string and did a select ... to_char ( date_column, 'dd.mm.yyyy' ) which broke the sorting but gave me the filter-options my users wanted. Specifing the date as yyyy.mm.dd is not an option for my users.
    Is it possible to get a filter which shows the "real" data and keeps the right sort order ?
    Regards and thanks
    Markus

    Markus,
    I've come up against this too. A varchar column gives you the selection list but no filtering using <,>,between etc., but a date column doesn't show the discrete data values. Users tend to ask for both, and putting both date and varchar columns in the report or using an LOV isn't very elegant.
    Is there anything significant about the dates the users want to search directly on? Judging from your 21.06.2000 example I'd guess not, but if so you can build your own column in the SELECT statement and use that for filtering/creating default reports.
    regards,
    Malcolm.
    Edited by: MalcA on Feb 16, 2012 11:39 AM

  • GL Trial Balance Report Query with date Effectivity

    We have a requirement to show the GL Trial Balance report with Effective dates as Parameters.
    Current Analysis:
    The Journals get updated with corresponding CCID in GL_BALANCES table when the Journal is posted. GL_BALANCE is SOB specific, if the SOB has month as period then the balances in GL_BALANCES would get updated against the month(period).
    To overcome the period problem, we explored the option of using a View based on GL_JE_HEADERS and GL_JE_LINES for 'Posted' Journal Batches of a SOB. We are checking whether the GL_JE_HEADERS.default_effective_date lies between the :p_from_date and :p_to_date which is sent to the Report as a parameter. The above idea does not return expected data when the custom Trial Balance Report is run.
    Following is the Query we have written for it:
    SELECT cc.segment4 ACCOUNT, bal.code_combination_id,
    bal.begin_balance_dr
    + SUM (NVL (gljel.accounted_dr, 0)) opening_bal_dr,
    bal.begin_balance_cr
    + SUM (NVL (gljel.accounted_cr, 0)) opening_bal_cr,
    ffv.description,
    (SELECT SUM (NVL (gljel.accounted_dr, 0))
    FROM gl_je_headers gljeh,
    gl_je_lines gljel,
    gl_code_combinations gcc
    WHERE gljeh.default_effective_date BETWEEN :p_from_date
    AND :p_to_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.code_combination_id = gcc.code_combination_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND gljeh.actual_flag = 'A'
    --AND gljel.code_combination_id =
    -- bal.code_combination_id
    AND gcc.segment4 = cc.segment4
    GROUP BY gcc.segment4) c_dr,
    (SELECT SUM (NVL (gljel.accounted_cr, 0))
    FROM gl_je_headers gljeh,
    gl_je_lines gljel,
    gl_code_combinations gcc
    WHERE gljeh.default_effective_date BETWEEN :p_from_date
    AND :p_to_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.code_combination_id = gcc.code_combination_id
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND gljeh.actual_flag = 'A'
    AND gcc.segment4 = cc.segment4
    GROUP BY gcc.segment4) c_cr
    FROM gl_period_statuses per,
    gl_code_combinations cc,
    gl_balances bal,
    gl_je_headers gljeh,
    gl_je_lines gljel,
    fnd_flex_values_vl ffv,
    fnd_flex_value_sets ffvs
    WHERE cc.chart_of_accounts_id = :p_chart_of_accts_id
    AND bal.currency_code = :p_currency
    AND bal.actual_flag = 'A'
    AND bal.period_name = per.period_name
    AND cc.template_id IS NULL
    AND cc.code_combination_id = bal.code_combination_id
    AND per.set_of_books_id = :p_set_of_books_id
    AND per.application_id = 101
    AND :p_from_date BETWEEN per.start_date AND per.end_date
    AND gljeh.period_name = per.period_name
    AND gljeh.default_effective_date <= :p_from_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND ffv.flex_value_set_id = ffvs.flex_value_set_id
    AND ffvs.flex_value_set_name = 'JSWEL_ACCOUNT'
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND cc.summary_flag = ffv.summary_flag
    AND cc.segment4 = ffv.flex_value
    AND gljeh.actual_flag = 'A'
    AND gljel.code_combination_id = bal.code_combination_id
    GROUP BY bal.begin_balance_dr,
    bal.begin_balance_cr,
    cc.segment4,
    ffv.description,
    bal.code_combination_id
    The problem is that not all expected columns are being queried. Kindly advise as appropriate.
    Note: I have also posted this thread on the Financials forum. Posting here to present the query to a larger audience with the expectation that my query would be answered.
    Thanks & Regards
    Sumit

    suggest to create customize TB report.

  • Query with date variable selection

    Greetings,
    I am having problems with a SQL Query and wondering if someone could help me out.  I have the following query and want to specify a WHERE clause and have the user select the date range they want to work with.  If I specify a date the query runs fine.  If I enter in the [%0] I get an error message saying: "incorrect syntax near '<'.
    Any help would be appreciated.
    select
    'W' as prefix,
    empid as [Employee Number] ,
    U_PayrollCat as [Payroll Category Code],
    '' as [Cost Center Code],
    ContractID as     [Job Center Code],
    Segment_0 + isnull( ActSep + Segment_1, '') + isnull(ActSep  + Segment_2, '') 
                          + isnull(ActSep + Segment_3, '') + isnull(ActSep + Segment_4, '') 
                          + isnull( ActSep  + Segment_5, '') + isnull(ActSep + Segment_6, '')
                          + isnull(ActSep + Segment_7, '') + isnull(ActSep  + Segment_8, '')
                          + isnull( ActSep + Segment_9, '') as [GL Account Code],
    quantity as Units,
    U_NBS_ITEMCOST/quantity as Rate,
    U_NBS_ITEMCOST as Amount,
    oclg.notes as Comments,
    oclg.recontact as [WorkDate],
    '' as[Department code]
    from
    oclg inner join
    dln1 on dln1.docentry =oclg.docentry inner join 
    odln on odln.docentry = dln1.docentry inner join
    ohem on ohem.userid = oclg.attenduser
    inner join oitm on oitm.itemcode = dln1.itemcode
    inner join oscl on oscl.callid = odln.U_NBS_S1Link
    inner join OACT on  OACT.AcctCode = dln1.cogsAcct
    inner join oadm on 1=1
    WHERE
    oclg.recontact >= [%0] AND oclg.recontact <= [%1]

    Gordon,
    That worked with a few modifications.  Removed comma on line before FROM clause and my UDF for Payroll Category is on my OITM table.  Complete Query looked like this:
    SELECT 'W' as prefix, t3.empid as 'Employee Number',
    t4.U_PayCat as 'Payroll Category Code',
    t5.ContractID as 'Job Center Code',
    t6.Segment_0 + isnull( ActSep + t6.Segment_1, '') + isnull(ActSep + t6.Segment_2, '')
    + isnull(ActSep + t6.Segment_3, '') + isnull(ActSep + t6.Segment_4, '')
    + isnull( ActSep + t6.Segment_5, '') + isnull(ActSep + t6.Segment_6, '')
    + isnull(ActSep + t6.Segment_7, '') + isnull(ActSep + t6.Segment_8, '')
    + isnull( ActSep + t6.Segment_9, '') as 'GL Account Code',
    t1.quantity as Units,
    t1.U_NBS_ITEMCOST/t1.quantity as Rate,
    t1.U_NBS_ITEMCOST as Amount,
    t0.notes as Comments,
    t0.recontact as WorkDate
    from dbo.oclg t0
    inner join dbo.dln1 t1 on t1.docentry =t0.docentry
    inner join dbo.odln t2 on t2.docentry = t1.docentry
    inner join dbo.ohem t3 on t3.userid = t0.attenduser
    inner join dbo.oitm t4 on t4.itemcode = t1.itemcode
    inner join dbo.oscl t5 on t5.callid = t2.U_NBS_S1Link
    inner join dbo.OACT t6 on T6.AcctCode = t1.cogsAcct
    inner join dbo.oadm t7 on 1=1
    WHERE t0.recontact >= '[%0]' AND t0.recontact <= '[%1]'
    Thanks for the help,
    Aaron

  • Jdev 10.1.3 and JSF  "comandlink component" don't work with Data filter

    I´m working in JSF with Jdeveloper 10.1.3 and Oc4j .
    I have a problem.
    I have .jspx where display employees of the company.
    The field employeeid have "comandlink component" with action "control.editemployee"
    when I fetch all data comandlink work OK.
    But I filter data by field, example Employee name Command link not work
    Help me, please.

    thanks
    i'm a little bit confused by the fact that jsf in 10.1.3 preview use managed bean (instead of data control) to get/put data from the model layer.
    we are using entity bean and session facade. In 9.0.5.2 we are using dto and data control to generate our jsp.
    we are currently testing/discovering jsf and search the best way to efficiently generate our ui's
    what is right way for jsf
    a) managed bean (if it is possible with session bean)
    b) data control when/if available
    and why ?

Maybe you are looking for

  • HP Officejet Pro 8600 - Google Cloud Print

    Hi, I use google cloudprint to print my 8600 from my chromebook.  Within the cloudprint dialog, the settings always default to gray scale with 300 dpi.  I can't seem to find a way to change these defaults - I don't see any configuration information t

  • IMac 17" Hard Drive and DVD dead after install.

    I am attempting to install a WD 250gig hard drive into a 17" flat panel 800mhz imac. I followed the directions of taking the base apart and installing the new drive with great care. The Original 80 gig drive was set to master and the DVD drive was se

  • Error with downlaod assistand and CS6 MS

    Two part question: I am trying to download a Adobe purchased CS6 Master Suite and I am unable to download the Download Assistant.  However, I get a problem that says my current download assistant has been "mis-configured" and I should contact the "au

  • How to Binding the MainPage's variable in XAML

    public sealed partial class MainPage : Page public double StatusbarOpacity { get; set; }//Slider's value binding public MainPage() this.InitializeComponent(); <Slider Value="{Binding StatusbarOpacity}" Maximum="100" Background="DarkOrange" BorderBrus

  • IWeb and iTunes Playlist Question:

    Hi, I would like to add an iTunes-Playlist to my Website. When I select the Playlist in the Media-Browser, iWeb creates a List with arrows pointing to the right. They are the same as they are in the iTMS. Where do they point?? Dirk