Adding  bp balance in following query

hello sir,
         u given me good solution but we want to add two rows in following query
1.  business parner closing balance
2.    checks on account amount.
select
DocNum, CardCode, CardName, DocDate, DocDueDate
from
OINV
where
datediff(dd, DocDueDate, getdate()) >= 0
and CANCELED = 'N'
and PaidToDate < DocTotal
regards ,

Hi,
Here's the query with the BP account balance added. I'm not sure what you mean by the 'checks on account amount'. Please clarify.
select
     T0.DocNum, T0.CardCode, T0.CardName,
     T0.DocDate, T0.DocDueDate, T1.Balance
from
     OINV T0
     inner join OCRD T1 on T0.CardCode = T1.CardCode
where
     datediff(dd, T0.DocDueDate, getdate()) >= 0
     and T0.CANCELED = 'N'
     and T0.PaidToDate < T0.DocTotal
Kind Regards,
Owen

Similar Messages

  • Problem in finding Exact result by using the following Query

    Hello,
    I am finding difficulty in producing the required result by using the following Query in Reports 6i
    (Note: - The query actual output and the required output are as follows: -)
    SELECT
    DISTINCT
    SH.S_HEAD_CODE,
    B.BILL_ID,
    B.SANCTION_DATE,
    E.EMP_NAME,
    E.EMP_DESIGNATION,
    B.TOTAL_BILL,
    NVL((SH.INITIAL_ALLOCATION-B.TOTAL_BILL), 0) BALANCE
    FROM BILL B, PARAMETERS P,SUB_HEAD SH, EMPLOYEES E, BILL_DETAIL BD
    WHERE
    SH.S_HEAD_CODE=B.S_HEAD_CODE
    AND B.S_HEAD_CODE=BD.S_HEAD_CODE
    AND B.EMP_ID_NO=E.EMP_ID_NO
    AND B.BILL_ID=BD.BILL_ID
    The Output of the above query is as follows: -
    Let say we have Total Amount Sanctioned Rs. 15,000,00/-
    Name Total Bill (Rs.) Balance (Rs.)
    Sohail 7147 1492853
    Saqib 2131 1497869
    Amir 6802 1493198
    Shafiq 1214 1498786
    Note:- In the above output the above query is subtracting the current balance from Total Sanctioned Amount (Rs. 1500000) each time, but
    it should actually subtract the current bill amount from the previous balance like the below said result.
    Name Total Bill (Rs.) Balance (Rs.)
    Sohail 7147 1492853 {Previous Balance - Current Bill Amount (1500000-7147) }........ The previous balance was actual amount Rs. 1500000
    Saqib 2131 1490722 {Previous Balance - Current Bill Amount (1492853 - 2131)}
    Amir 6802 1483920 {Previous Balance - Current Bill Amount (1490722 - 6802)}
    Shafiq 1214 1482706 {Previous Balance - Current Bill Amount (1483920 - 1214)}
    Results Continue...........................
    Please help me to solve this problem.
    Thank you in advance

    just check if this meets your requirements,
    SQL>
    SQL> With t As
      2  (
      3  Select 'Sohail' c1 ,7147 c2 ,1492853 c3 From dual Union All
      4  Select 'Saqib'   ,2131 ,1497869         From dual Union All
      5  Select 'Amir'    ,6802 ,1493198         From dual Union All
      6  Select 'Shafiq' ,1214 ,1498786          From dual
      7  )
      8  Select c1,
      9         c2,
    10         prv_amt - c2 current_amt
    11  From
    12  (
    13  Select c1,
    14         c2,
    15         c3,
    16         lag(c3,1,1500000) over(Order By c3) prv_amt
    17  From t
    18  );
    C1             C2 CURRENT_AMT
    Sohail       7147     1492853
    Amir         6802     1486051
    Saqib        2131     1491067
    Shafiq       1214     1496655
    SQL>

  • How to add a receipt number in the following Query for PO Report

    Hi Guys,
    I need a help regarding following query.
    Its a PO report for 11.5.10.2
    select distinct pv.segment1 supplier_number,
    pv.vendor_name supplier_name,
    pha.segment1 po_number,
    pha.revision_num revision_num,
    pha.authorization_status po_status,
    to_char(pha.creation_date, 'DD/MM/YYYY') creation_date,
    pha.currency_code currency_code,
    pla.sum_amount_ordered sum_amount_ordered,
    pda.sum_quantity_ordered sum_quantity_ordered,
    pda.sum_amount_received sum_amount_received,
    pda.sum_quantity_received sum_quantity_received,
    (pla.sum_amount_ordered - pda.sum_amount_received) sum_accrued, --AVI
    ( pda.sum_quantity_ordered - pda.sum_quantity_received) quantity_accrued, --AVi
    to_char(rsl.date_receipt, 'DD/MM/YYYY') date_receipt,
    -- rsl.receipt_num receipt_number,
    ppa.segment1 project_code, ppa.project_status_code, --10.0.0.4
    aia.invoice_num invoice_num,
    aia.invoice_date invoice_date, --AVI 
    aia.creation_date invoice_creation_date, --AVI 
    aia.amount invoice_amount_allocated_to_po, --AVI
    pla.purchase_basis,
    pla.category_id,
    -- pda.item_description,
    haou.name organisation, --10.0.0.3
    pda.sum_quantity_billed sum_quantity_billed , --10.0.0.3
    gcc1.CONCATENATED_SEGMENTS,
    gcc2.CONCATENATED_SEGMENTS
    from po_headers_all pha,
    po_vendors pv,
    pa_projects_all ppa,
    hr_all_organization_units haou,
    (select po_header_id,
    sum(quantity * unit_price) sum_amount_ordered,
    org_id,
    purchase_basis,
    category_id
    -- pla.item_description,
    from po_lines_all
    group by po_header_id, org_id
    , purchase_basis,
    category_id
    -- pla.item_description
    ) pla,
    (select pla.po_header_id,
    pda.project_id,
    sum(pda.quantity_ordered) sum_quantity_ordered,
    sum(pda.quantity_delivered * pla.unit_price) sum_amount_received,
    sum(pda.quantity_delivered) sum_quantity_received,
    sum(pda.quantity_billed) sum_quantity_billed, --10.0.0.3
    accrual_account_id
    from po_distributions_all pda, po_lines_all pla
    where pla.po_line_id = pda.po_line_id
    group by pla.po_header_id, pda.project_id,accrual_account_id
    ) pda,
    (select po_header_id, charge_account_id,
    -- rsh.receipt_num,
    min(rsl.creation_date) date_receipt
    from rcv_shipment_lines rsl
    where rsh.SHIPMENT_HEADER_ID=rsl.SHIPMENT_HEADER_ID
    group by po_header_id,charge_account_id
    ) rsl,
    (select distinct aia.invoice_num, pda.po_header_id , aia.invoice_date --10.0.0.3
    , aia.creation_date , sum(aida.amount) amount
    from po_distributions_all pda,
    ap_invoice_distributions_all aida,
    ap_invoices_all aia
    where pda.po_distribution_id = aida.po_distribution_id(+)
    and aia.invoice_id(+) = aida.invoice_id
    Group by
    aia.invoice_num, pda.po_header_id , aia.invoice_date --10.0.0.3
    , aia.creation_date) aia,
    (select haou2.organization_id, haou2.name
    from fnd_flex_value_sets ffvs,
    fnd_flex_value_norm_hierarchy ffvnh,
    fnd_flex_values_vl ffvv,
    hr_all_organization_units haou1,
    FND_FLEX_VALUE_CHILDREN_V ffvcv,
    hr_all_organization_units haou2
    where ffvs.FLEX_VALUE_SET_NAME = 'CAP_CODE_BU'
    and ffvs.FLEX_VALUE_SET_ID = ffvnh.flex_value_set_id
    and ffvnh.parent_flex_value like 'PO%'
    and ffvv.FLEX_VALUE_SET_ID = ffvnh.flex_value_set_id
    and ffvv.FLEX_VALUE between ffvnh.child_flex_value_low and ffvnh.child_flex_value_high
    and substr(haou1.name, 1, Instr(haou1.name, '-')) =
    substr(ffvv.DESCRIPTION, 1, Instr(ffvv.DESCRIPTION, '-'))
    and haou1.organization_id = fnd_global.org_id
    and ffvcv.parent_flex_value = ffvnh.parent_flex_value
    and ffvcv.flex_value_set_id = ffvs.flex_value_set_id
    and substr(haou2.name, 1, Instr(haou2.name, '-')) =
    substr(ffvcv.DESCRIPTION, 1, Instr(ffvcv.DESCRIPTION, '-'))
    union --10.0.0.1
    select f.organization_id, f.name --10.0.0.1
    from hr_all_organization_units f --10.0.0.1
    where f.organization_id = fnd_global.ORG_ID --10.0.0.1
    ) bu
    , po_line_locations_all plla --10.0.0.4
    , gl_code_combinations_kfv gcc1
    ,gl_code_combinations_kfv gcc2
    where pv.vendor_id = pha.vendor_id
    and pla.po_header_id = pha.po_header_id
    and pda.po_header_id = pha.po_header_id
    and pha.po_header_id = rsl.po_header_id(+)
    and pda.project_id = ppa.project_id(+)
    and pha.po_header_id = aia.po_header_id(+)
    and aia.po_header_id = pha.po_header_id
    and pla.org_id = haou.organization_id
    and pha.authorization_status in ('APPROVED', 'OPEN')
    and plla.po_header_id = pha.po_header_id --10.0.0.4
    and plla.closed_code in ('APPROVED', 'OPEN', 'CLOSED FOR INVOICE', 'CLOSED FOR RECEIVING', 'CANCELLED') --10.0.0.4
    and bu.organization_id = haou.organization_id
    AND gcc1.code_combination_id = pda.accrual_account_id
    AND gcc2.code_combination_id =rsl.CHARGE_ACCOUNT_ID
    In the following query I have commented receipt_num using the table rcv_transaction_headers.
    If I uncomment it the query results huge number of unexpected report.
    How can I add receipt number to the following query?
    Should I use rcv_transactions. If yes, what would be the join conditions.
    Kindly help as its urgent.
    Thanks in advance.
    Regards
    Avijit

    Sandeep is correct. I don't have time to tell you the correct query, but mine is something like this based on Sandeep's information:
    SELECT rsh.receipt_num
    FROM   rcv_transactions      rcvt,
           po_lines_all          pla,
           rcv_shipment_headers  rsh
    WHERE  rcvt.shipment_header_id   = rsh.shipment_header_id
    AND    rcvt.PO_LINE_ID          = pla.PO_LINE_ID
    AND    pla.item_id              = (select distinct inventory_item_id
    from mtl_system_items
    where segment1 = '1216107-2')

  • Need help in the following query

    Hi ,
    I have the following query to pull out data for a particular timeperiod( campaign)
    select
    da.acct_nr,smas.mrkt_id,smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,
    smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,prev.*
    From cdw.sum_mrkt_acct_sls smas
    join codi.dim_acct da
    on (smas.mrkt_id = da.mrkt_id and smas.acct_key = da.acct_key)
    join codi.dim_acct da1
    on (smas.mrkt_id = da1.mrkt_id and smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in
    select dwnln_acct_key from codi.dim_ldrshp_genlgy
    where mrkt_id = 66 and fld_sls_cmpgn_perd_id = 20100304
    and root_upln_acct_key = (select acct_key from codi.dim_acct where acct_nr = '0032622' and mrkt_id = 66)
    and
    smas.mrkt_id = 66
    and smas.fld_sls_cmpgn_perd_id = 20100304
    and smas.sls_org_key <> -100
    order by 1
    So this query will pull out data for campaign 20100304
    No i want to modify the query to pull out data for 3 such campaigns.
    for a smas.acct_key
    so data will
    smas.acct_key all the data for 1st campaign , all the data for 2nd campaign. all the data for 3rd campaign
    Could you please help in modifying this query.
    Thanks

    How about this ??
    select da.acct_nr,
           smas.mrkt_id,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           prev.*
      From cdw.sum_mrkt_acct_sls smas
      join codi.dim_acct da on (smas.mrkt_id = da.mrkt_id and
                               smas.acct_key = da.acct_key)
      join codi.dim_acct da1 on (smas.mrkt_id = da1.mrkt_id and
                                smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in (select dwnln_acct_key
                               from codi.dim_ldrshp_genlgy
                              where mrkt_id = 66
                                and fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
                                and root_upln_acct_key =
                                    (select acct_key
                                       from codi.dim_acct
                                      where acct_nr = '0032622'
                                        and mrkt_id = 66))
       and smas.mrkt_id = 66
       and smas.fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
       and smas.sls_org_key - 100
    order by 1

  • The following query failed: GetUserProfileByName - with the wrong username

    I have 2 users (out of 800), who run into this issue on occasion. Their username is 'fccs\user1' in the profile db, and in every UserInfo table in the system. But when they try to go to certain sites or open an infopath form, this error gets thrown:
    The following query failed: GetUserProfileByName (User: FCCS\[email protected], Form Name: Template, IP: , Connection Target: , Request: http://fccsteams/sites/DataManagement/Tasks/Lists/Tasks/Folders1.aspx?RootFolder=/sites/DataManagement/Tasks/Lists/Tasks/2013/11&, Form ID: urn:schemas-microsoft-com:office:infopath:list:-AutoGen-2013-08-05T23:14:53:458Z Type: DataAdapterException, Exception Message: The remote server returned an error: (500) Internal Server Error.  Operation Failure ---> Access Denied: To create a user profile, you must be an administrator, or create your own profile and have personal features rights.  UnauthorizedAccessAccess Denied: To create a user profile, you must be an administrator, or create your own profile and have personal features rights. The remote server returned an error: (500) Internal Server Error.)
    Notice how the username is now the entire email address and not just the username. I have no idea why it thinks that that is their username. Any ideas?

    Hi,
    According to your post, my understanding is that you got query failed error.
    Melick had written a blog said that the form access the user profile web service (Userprofileservice.asmx) using  UDC
    file.
    You can check whether the UDC connection was still pointing to root site.
    You can change this file to match with the sub site collection. Otherwise there may be a cross domain access issue.
    There are similar threads for your reference.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/9c2f7f4c-0fa9-43bd-94b1-1d7075e35841/5566-error-with-getuserprofilebyname-and-infopah-browser-forms-using-claims-based-authentication
    http://social.msdn.microsoft.com/Forums/en-US/49753330-40c0-4327-9a9b-2c3304a74e67/sharepoint-infopath-and-populating-forms-with-ad-data?forum=sharepointcustomizationlegacy
    Thanks & Regards,
    Jason 
    Jason Guo
    TechNet Community Support

  • Issue converting the following query to text.

    Hello guys, I'm trying to convert the following query to text and to use PRINT so that it returns theresult in the picture as output, help would be appreciated, thanks :)SELECT EventName, EventDate
    FROM EventTable
    ORDER BY EventDate DESC;

    This is an example, As I said it is not a good approach
    set nocount on
    declare @tab table(id int,txt varchar(100));
    declare @txt varchar(1000);
    declare @count int;
    insert into @tab
    values(1,'Text 1'),(2,'Text 2'),(4,'Text 4');
    select *,RN=ROW_NUMBER()OVER(ORDER BY (SELECT NULL)) into #temp from @tab
    select @count=@@ROWCOUNT;
    while @count>0
    begin
    select @txt =right(replicate(' ',50)+convert(varchar(50),ID),50) +
    right(replicate(' ',50)+convert(varchar(50),txt),50)
    from #temp where RN=@count
    set @count=@count-1
    print @txt
    end
    drop Table #temp
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Outer join combination fails in following query

    Hi All,
    Join on table fails in following scenario,
    --Employee table  
    CREATE TABLE "EMP"
       ("EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
         "FNAME" NVARCHAR2(50) NOT NULL ENABLE,
         "LNAME" NVARCHAR2(50) NOT NULL ENABLE
    --Mapping between Task type & Department
       CREATE TABLE "TASKTYPE_FOR_DEPT"
       (     "TASKTYPE_FOR_DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
         "DEPT_ID" NUMBER(10,0) NOT NULL ENABLE,
         "TASK_TYPE_CD" NVARCHAR2(10) NOT NULL ENABLE
    -- Departmentwise employee hierarchy  
    CREATE TABLE "EMP_HIERARCHY"
       (     "EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
         "DEPT_ID" NUMBER(10,0) NOT NULL ENABLE
       -- Tasks Details
    CREATE TABLE "TASKS"
       (     "TASK_ID" NUMBER(10,0) NOT NULL ENABLE,
         "TASK_PRIORITY" NVARCHAR2(10) NOT NULL ENABLE,
         "TASK_TYPE" VARCHAR2(20 BYTE)
       -- Tasks allocation
    CREATE TABLE "TASKSALLOCATION"
       (     "TASKALLOCATION_ID" NUMBER(10,0) NOT NULL ENABLE,
         "EMP_ID" NUMBER(10,0) NOT NULL ENABLE,
         "TASK_ID" NUMBER(10,0) NOT NULL ENABLE
    Insert into EMP (EMP_ID,FNAME,LNAME) values (1,'XYZ','DFD');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (2,'DFDS','FD');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (3,'FDSF','GFH');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (6,'GFHGF','GFHS');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (4,'GFD','FDG');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (5,'DSFDS','FDSAF');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (7,'GHGY','EWE');
    Insert into EMP (EMP_ID,FNAME,LNAME) values (8,'FGRFSAD','SADF');
    Insert into TASKTYPE_FOR_DEPT (TASKTYPE_FOR_DEPT_ID,DEPT_ID,TASK_TYPE_CD) values (1,1,'T1');
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (1,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (2,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (3,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (4,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (5,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (6,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (7,1);
    Insert into EMP_HIERARCHY (EMP_ID,DEPT_ID) values (8,1);
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (1,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (2,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (3,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (4,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (5,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (6,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (7,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (8,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (9,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (10,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (11,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (12,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (13,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (14,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (15,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (16,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (17,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (18,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (19,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (20,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (21,'LOW','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (22,'HIGH','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (23,'MEDIUM','T1');
    Insert into TASKS (TASK_ID,TASK_PRIORITY,TASK_TYPE) values (24,'LOW','T1');
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (1,1,1);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (2,2,1);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (3,3,2);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (4,3,3);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (5,4,4);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (6,4,5);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (7,4,6);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (8,4,7);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (9,5,6);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (10,6,8);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (12,8,8);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (13,8,10);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (14,8,11);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (15,8,12);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (16,6,13);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (17,5,14);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (18,3,12);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (19,3,13);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (20,2,15);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (21,1,16);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (22,2,17);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (23,1,18);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (24,4,19);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (25,6,20);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (26,5,21);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (27,1,22);
    Insert into TASKSALLOCATION (TASKALLOCATION_ID,EMP_ID,TASK_ID) values (28,3,23);
    COMMIT;We want all resources belongs to department for a given case type with assinged tasks count & grouping with priority.
    I tried the following query,
    select emp.fname || ' ' || emp.lname EMP_NAME
         , sum(DECODE(tasks.TASK_PRIORITY, 'HIGH', 1, 0)) HIGH
         , sum(DECODE(tasks.TASK_PRIORITY, 'MEDIUM', 1, 0)) MEDIUM
         , sum(DECODE(tasks.TASK_PRIORITY, 'LOW', 1, 0)) LOW
      from emp,
      EMP_HIERARCHY,
      TASKSALLOCATION,
      TASKS,
      TASKTYPE_FOR_DEPT 
      where
       TASKTYPE_FOR_DEPT.TASK_TYPE_CD = 'T1'
       emp.EMP_ID = TASKSALLOCATION.EMP_ID(+)
      and TASKSALLOCATION.TASK_ID = tasks.TASK_ID(+)
      and tasks.TASK_TYPE = TASKTYPE_FOR_DEPT.TASK_TYPE_CD
      and TASKTYPE_FOR_DEPT.dept_id = EMP_HIERARCHY.dept_id
    -- and EMP_HIERARCHY.emp_id = emp.EMP_ID
    group by emp.fname || ' ' || emp.lname;
    It is not working properly.
    Actually we are also looking the employee for whom task has been not allocated but belong to same department.
    In above resultset employee 'GHGY EWE' belongs to same department but no taks is allocated.
    We are expecting resultset something like this.
    with
        t as
              select     'GFHGF GFHS' as emp_name, 1 as highPriority,     2 as mediumPriority, 0 as lowPriority FROM dual union all
              select     'FDSF GFH',               1     ,     2     ,     2     FROM dual union all
              select     'XYZ DFD'     ,          3     ,     0     ,     1     FROM dual union all
              select     'GHGY EWE',          0     ,     0     ,     0     FROM dual union all
              select     'DFDS FD',               1     ,     1     ,     1     FROM dual union all
              select     'GFD FDG',               3     ,     1     ,     1     FROM dual union all
              select     'FGRFSAD SADF',          1     ,     2     ,     1     FROM dual union all
              select     'DSFDS FDSAF',          0     ,     1     ,     2     FROM dual
              );Note : We are using Oracle 11.2.0.2.0 version

    I do not know your design, so you will have to change left join with plain join where appropriate. Otherwise:
    select  emp1.fname || ' ' || emp1.lname EMP_NAME,
            sum(DECODE(tasks.TASK_PRIORITY, 'HIGH', 1, 0)) HIGH,
            sum(DECODE(tasks.TASK_PRIORITY, 'MEDIUM', 1, 0)) MEDIUM,
            sum(DECODE(tasks.TASK_PRIORITY, 'LOW', 1, 0)) LOW
      from      emp1
            left join
                EMP_HIERARCHY
              on EMP_HIERARCHY.emp_id = emp1.EMP_ID
            left join
                TASKTYPE_FOR_DEPT
              on (
                      TASKTYPE_FOR_DEPT.TASK_TYPE_CD = 'T1'
                  and
                      TASKTYPE_FOR_DEPT.dept_id = EMP_HIERARCHY.dept_id
            left join
                TASKSALLOCATION
              on emp1.EMP_ID = TASKSALLOCATION.EMP_ID
            left join
                TASKS
              on (
                      tasks.TASK_TYPE = TASKTYPE_FOR_DEPT.TASK_TYPE_CD
                  and
                      tasks.TASK_ID = TASKSALLOCATION.TASK_ID
      group by emp1.fname || ' ' || emp1.lname
    EMP_NAME                   HIGH     MEDIUM        LOW
    FGRFSAD SADF                  1          2          1
    XYZ DFD                       3          0          1
    GHGY EWE                      0          0          0
    GFHGF GFHS                    1          2          0
    GFD FDG                       3          1          1
    DFDS FD                       1          1          1
    FDSF GFH                      1          2          2
    DSFDS FDSAF                   0          1          2
    8 rows selected.
    SQL> SY.

  • Can u write the following query without using group by clause

    select sp.sid, p.pid, p.name from product p, supp_prod sp
    where sp.pid= p.pid and
    sp.sid = ( select sid from supp_prod group by sid
    having count(*) =(select count(*) from product));
    thru this, we retrieving all the products delivered by the supplier.
    Can you write the following query without using the group by clause

      select sp.sid, p.pid, p.name
        from product p, supp_prod sp
       where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
    maybe if you can post some sample data and output will help us understand what you want to achieve.

  • How Can I make the following query faster

    Hi Guru
    I want your valuable suggestion to make the following query faster.I did not write all required columns list. I gave here all those columns where I have conditon like decode,case when,or subquery
    (SELECT CASE WHEN REPORTED_BY IS NULL THEN
              (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.EMP_NO_RADIO)
         ELSE (SELECT INITCAP(EMP_NAME) FROM HR_EMP WHERE EMP_NO = M.REPORTED_BY) END RADIOLOGIST_NAME,
         (SELECT TEAM_NAME FROM DC_TECHTEAMMST WHERE TEAM_NO = M.GROUP_NO) GROUP_NAME,
         CASE WHEN M.RESULT_ENTRY_LOCK_BY IS NOT NULL THEN 'R'
    WHEN M.REPORT_DONE = 'D' THEN 'D'
    WHEN M.REPORT_DONE = 'P' THEN 'P'
    WHEN M.REPORT_DONE = 'F' THEN 'F'
         WHEN NVL(M.IMG_CAPTURED,'X') NOT IN ('B','Y') OR M.QA_RESULT = 'F' THEN 'S'
    WHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') NOT IN ('B','P') THEN 'Q'
         wHEN NVL(M.IMG_CAPTURED,'X') IN ('B','Y') AND NVL(M.QA_RESULT,'X') IN ('B','P') THEN 'C'
    END STATUS,
         (SELECT DECODE(NVL(V.DELIVERY_STATUS,'N'),'E',3,'U',2,1)
              FROM FN_VOUCHERCHD V WHERE V.VOUCHER_NO = M.VOUCHER_NO AND V.ITEM_NO = M.TEST_NO) DELIVERY_STATUS,
         trunc((start_time-order_end)*24,0)||' hr'||':'||
         decode(length(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)),2,to_char(trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0))
              ,1,to_char('0'||trunc(to_char(MOD((M.start_time-M.order_end)*24,1)*60),0)))||' mi' duration_order_capture,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',NVL(R.NAME,R.name_lang_name||' '||R.name_lang_fname)) PAT_NAME,
         FNC_PATIENTAGE(R.REG_NO,'',R.CONFIDENTIAL_PATIENT) pat_age,
         DECODE(R.CONFIDENTIAL_PATIENT,'Y','*',R.PATIENT_SEX) PAT_SEX
    FROM DC_MODALITYAPPOINTMENT M,DC_TESTMST T,OP_REGISTRATION R
    WHERE M.ACCESSION_NO IS NOT NULL AND NVL(M.CANCEL_FLAG,'N') = 'N'
    AND (NVL(T.SP_GEN,'S') = 'S' OR NVL(M.DOC_REQ_GEN,'N') = 'Y')
    AND M.TEST_NO IS NOT NULL AND M.TEST_NO = T.TEST_NO AND M.REG_NO = R.REG_NO)
    How can I make the above query faster.
    Query condition or indexing whatever is preferable please guide me.
    The approximate data of tables
    DC_MODALITYAPPOINTMENT 2,000,000
    A lot of updating is going on some columns of this table.all columns are not in the select list, Insertion is happend in batch process by back-end trigger of another table.
    Primary key based one column,
    OP_REGISTRATION 500,000
    Daily insertion on this table around 500 records,updation is not much.
    Primary key based one column 'reg_no'
    DC_TESTMST
    Total records of this table not more than 1500.This is setup table. Insertion and updation is not much on this table also
    I have to create a view based on this query .
    and I have to create another view to serve another purpose.
    In the 2nd view I need this query as well as I need another query by using union all operator based on a table(dc_oldresult)
    which have 1,600,000 records.There is no DML on this table
    SELECT      NVL((SELECT USER_DEFINE_TEST_NO FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ),SV_ID) USER_D_EXAM_NO,
    (SELECT TEST_TYPE FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1 ) EXAM_TYPE,
         NVL((SELECT TEST_NAME FROM DC_TESTMST WHERE TEST_NO = SV_ID AND ROWNUM = 1),'Exam Code: '||sv_id) EXAM_NAME,
         (SELECT PAT_NAME FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_NAME,
         (SELECT PAT_AGE FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_AGE,
         (SELECT PAT_SEX FROM OP_REGISTRATION WHERE REG_NO = HN) PATIENT_GENDER
    FROM DC_OLDRESULT
    WHERE HN IS NOT NULL AND SV_ID IS NOT NULL AND UPPER(ACTIVE) = 'TRUE'
    Should I make join DC_OLDRESULT, OP_REGISTRATION and DC_TESTMST? or The eixisting subquery is better?
    I use OP_REGISTRATION and DC_TESTMST in both query
    Thanks in advance
    Mokarem

    When your query takes too long ...

  • Write the following query using JOIN keyword ?

    Qest:
    Write the following query using JOIN keyword ?
    select ID_category from category_master X
    where Exist(select 1 from sub_category Y where
    X.ID_category=Y.ID_category)Edited by: 799660 on Oct 3, 2010 6:05 AM

    select  X.ID_category
      from  category_master X join (select distinct ID_category from sub_category) Y
             on (X.ID_category=Y.ID_category)
    /SY.

  • How to convert the following query to sql server 2005

    hi
    i have the following query in ms access and i want to convert it into sql server 2005 express edition
    SELECT iif(Max(BNo) is null,1,Max(BNo)+1) AS BNo from ( SELECT iif(Max(Product.BNo) is null,0,Max(Product.BNo)) AS BNo FROM Product union all SELECT iif(Max(grndetail.BNo) is null,0,Max(grndetail.BNo)) AS BNo FROM grndetail UNION ALL SELECT iif(Max(srdetail.BNo) is null,0,Max(srdetail.BNo)) AS BNo FROM srdetail ) as t
    how to do this

    The construct involving case when MAX sounds suspicious. Can you explain what the query is supposed to be doing, the structure of your table, then we can re-write it?
    E.g. if you provide your table, some data and desired result, you'll get better answer than direct translation of this suspicious query.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Order by problem.......how to Ascending order by date from the following query

    hi
    i have following query to show the monthly sales after summing up monthly sales total but i have facing a problem this query is not properly perform order by clause according to the months like jan,feb,mar etc... please tell me where i made mistake
    SELECT     CashName AS AccountName, LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate) AS Months, SUM(Total) AS NetSales
    FROM         dbo.CashSales
    GROUP BY LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate), CashName

    Select AccountName, Months, NetSales from
    (SELECT CashName AS AccountName, LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate) AS Months, SUM(Total) AS NetSales,
    DATEADD(month, DATEDIFF(month, 0, CashDate), 0) as dt
    FROM dbo.CashSales
    GROUP BY LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate), CashName, DATEADD(month, DATEDIFF(month, 0, CashDate), 0)
    t
    Order By dt

  • Hpw to tune the performance of following query?

    Hi all,
               I want a particular set of G/L acct nos for the list of billing documents that i have in an internal table ie. pt_vbrk. I am using table BSIS.However ,when i use the following query it is taking  very very long time .I even tried using LOOP...ENDLOOP statement.Can anyone tell me how to enhance the performance of the query?Thanks in advance.
    i = 0.
    loop at pt_vbrk.
    i = i + 1.
    endloop.
    while j <= i.
    read table pt_vbrk index j.
    select single hkont  from bsis into  corresponding fields of
    pt_vbrk where
    ( hkont = '0013100000' or hkont = '0013105000'
    or hkont = '0013110000' or hkont = '0013112000'
    or hkont = '0013115000' or hkont = '0013120000'
    or hkont = '0013125000' or hkont = '0013135500'
    or hkont = '0013140000' or hkont = '0013145000'
    or hkont = '0013155000' or hkont = '0013165000'
    or hkont = '0013175000' or hkont = '0013170000' )
    and belnr = pt_vbrk-belnr and  gjahr = pt_vbrk-gjahr   . "#EC CI_NOFIRST
    modify pt_vbrk from pt_vbrk index j.
    j = j + 1.
    endwhile.
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Sep 22, 2009 9:06 AM

    Try the following approach.
    TYPES: BEGIN OF ty_bsis,
             bukrs TYPE bsis-bukrs,
             hkont TYPE bsis-hkont,
             augdt TYPE bsis-augdt,
             augbl TYPE bsis-augbl,
             zuonr TYPE bsis-zuonr,
             gjahr TYPE bsis-gjahr,
             belnr TYPE bsis-belnr,
             buzei TYPE bsis-buzei,
           END OF ty_bsis.
    DATA: w_bsis     TYPE                 ty_bsis ,
          w_index    TYPE                 sy-tabix,
          t_bsis     TYPE SORTED TABLE OF ty_bsis
            WITH NON-UNIQUE KEY bukrs belnr gjahr ,
          t_vbrk_tmp LIKE        TABLE OF pt_vbrk .
    RANGES: r_hkont FOR bsis-hkont.
    IF NOT pt_vbrk[] IS INITIAL.
      REFRESH r_hkont.
      r_hkont-sign   = 'I'.
      r_hkont-option = 'EQ'.
      r_hkont-low = '0013100000'.
      APPEND r_hkont.
      r_hkont-low = '0013105000'.
      APPEND r_hkont.
      r_hkont-low = '0013110000'.
      APPEND r_hkont.
      r_hkont-low = '0013112000'.
      APPEND r_hkont.
      r_hkont-low = '0013115000'.
      APPEND r_hkont.
      r_hkont-low = '0013120000'.
      APPEND r_hkont.
      r_hkont-low = '0013125000'.
      APPEND r_hkont.
      r_hkont-low = '0013135500'.
      APPEND r_hkont.
      r_hkont-low = '0013140000'.
      APPEND r_hkont.
      r_hkont-low = '0013145000'.
      APPEND r_hkont.
      r_hkont-low = '0013155000'.
      APPEND r_hkont.
      r_hkont-low = '0013165000'.
      APPEND r_hkont.
      r_hkont-low = '0013175000'.
      APPEND r_hkont.
      r_hkont-low = '0013170000'.
      APPEND r_hkont.
      t_vbrk_tmp[] = pt_vbrk[].
      SORT t_vbrk_tmp BY bukrs gjahr belnr.
      DELETE ADJACENT DUPLICATES FROM t_vbrk_tmp
        COMPARING bukrs gjahr belnr.
      SELECT bukrs
             hkont
             augdt
             augbl
             zuonr
             gjahr
             belnr
             buzei
        FROM bsis
        INTO TABLE t_bsis
        FOR ALL ENTRIES IN t_vbrk_tmp
        WHERE bukrs EQ t_vbrk_tmp-bukrs
        AND   hkont IN r_hkont
        AND   gjahr EQ t_vbrk_tmp-gjahr
        AND   belnr EQ t_vbrk_tmp-belnr.
      IF sy-subrc EQ 0.
        LOOP AT pt_vbrk.
          w_index = sy-tabix.
          READ TABLE t_bsis INTO w_bsis
            WITH KEY bukrs = pt_vbrk-bukrs
                     belnr = pt_vbrk-belnr
                     gjahr = pt_vbrk-gjahr
                     TRANSPORTING
                       hkont.
          IF sy-subrc EQ 0.
            pt_vbrk-hkont = w_bsis-hkont.
            MODIFY pt_vbrk INDEX w_index
              TRANSPORTING
                hkont.
          ENDIF.
        ENDIF.
      ENDIF.

  • Trouble adding multiple parameters to Command Query

    <p>I am trying to calculate the calendar days each unit is in use.  For each job a unit has a arrival date and a departure date. A unit may work on more than one job in a day, or on 1 job for more then 1 day</p><p>For example the table look like this, if I have unit #10 and it works as follows<br />Unit   Job        Arrival        Departure<br />10        1         Jan 1            Jan 1<br />10        2         Jan 2            Jan 3<br />10        3         Jan 3            Jan 3<br />10        4         Jan 5            Jan 6           <br /><br />And I want my report to show<br />Unit       Days worked<br />10         5<br /><br />So the Unit actually works on 5 days beween Jan 1 and Jan 6.  I am able to write a query to get this information but I am having trouble creating this in Crystal Reports XI.  I have tried adding my query to the report using "add Command" however when I try to replace my hard coded dates with parameters, I am able to add 1 parameter (From Date) but when I add the (To Date) paramater I get an error "Failed to retrieve data from database ORA00911- Invalid Character"  I&#39;m not sure why it doens&#39;t allow me to add the second date parameter.  I don&#39;t know if there is a better wa to do this within Crystal reports itself.</p>

    Please re-post if this is still an issue and please specify versions.

Maybe you are looking for

  • The 'Apps' tab in my Creative Cloud Desktop app shows a Download Error

    I have tried uninstalling, downloading, and reinstalling Creative Cloud Desktop and continue to get the Download Error prompt.  It either shows the Download Error prompt or it continues to just think and think and think.  All the other tabs work norm

  • How can I format an external hard drive to Fat 32?

    My brother wants to connect an external hard drive to his Sony PS3 for backup purposes. He bought a Western Digital 3TB "MyBook for Mac". The PS3 requires the drive to be Fat 32 format. So I hooked the drive up to my new-ish iMac and went into the Di

  • Use a flexible Filename in REPORT CSV OUTPUT

    -> ReportAttributes -> csv-output -> filename I tried to use &item. and :Item but it seems the FILENAME of the csv-output is fixed. But I would like to give a name depending from context. Any ideas ?

  • Some features/options needed when using mobileme gallery in iframe

    hi@all i have built this iweb site and embedded my mobilemegallery like this: <iframe width="1280" height="900 " frameborder="0" src="http://gallery.me.com/friereida#100008&view=mosaic&sel=0" more attributes> </iframe> so what i need is: how can i ac

  • Help with Page Parameters with PDK and/or PL/SQL

    Hello, I'm having difficulties get the real path of pages with PL / SQL. Another parameter that can not put the portlet in PL / SQL is the HTTP_REFERER. I read the PDK API but I could not understand how to use the HTTP_REFERER And as I get the realpa