Use of distinct in main query

Hi All,
I am creating a report based on two tables Invoice Header and Invoice Line. These two table have the following fields in relation :
Invoice_Dept|| Invoice_Pfx||Invoice_No
My question is whether I can use distinct in the main query for this. Coz, when I don't I get repeated records as one Invoice header can have multiple line items in the Invoice Line tables.
Please suggest.
Thanks

Hi Omer Farooq,
Firstly you can use Distinct in main query.
Secondly I feel you need to use Groups in the data model rather then using distinct.
If you will create groups then your first that is top group will contain fields related to Invoice Header
and second group will contain Invoice Line fields.
Hope this helps.
If this does not help please post your query and what output you want on the report.
Best Regards
Arif Khadas

Similar Messages

  • Passing YTD selection from a main query to a detailed query using RRI

    Hi,
    We have created two queries: one main query on an infocube for aggregated data, one detailed query on the feeding DSO for data at the level of sales document items.
    Both queries show monthly and YTD (year-to-date) actual cost figures.
    The user enters for instance the month of 05.2005 on the main query in a variable ZP_MONTH.
    A user exit variable ZS_YTD is calculated so that the interval 01.2005 - 05.2005 is stored in ZS_YTD.
    Revenues in the month are displayed in one column.
    Revenues in the YTD period are displayed in another column.
    Assume the data is displayed by document types.
    Then the user should select the document type and perform a jump target (Goto) to the detailed query to see which sales document items are contributing to the total revenues behind the document type.
    We have defined a ZS_YTD_2 variable on the detailed query.  It is used in the field assignments in the RSBBS transaction to receive the 0CALMONTH selection (in our case 01.2005 - 05.2005).  Then on the detailed query, we defined another userexit variable to capture the selected month based on ZS_YTD_2.
    Our issue is that when the user goes from the main query to the detailed query, the variable screen of the detailed query is being displayed with the variable ZS_YTD_2 open and the user can even change the selection there.
    Is it possible to remove the display of this intermediate variable screen?
    Thanks.

    Well.  If you unflag the variable for ready for input on the detailed query, then it is not possible for that variable to receive the period selected on the main query.  Even worse, the query crashes with the message that the variable is not correctly defined.
    Any other suggestion?
    Thanks.

  • How can I use the Rownum/Customized SQL query in a Mapping?

    Hi,
    * I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
    * How can I use an Dual table in OWB mapping?
    * Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
    Thanks in Advance
    Kishan

    Hi Niels,
    As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
    Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
    Hope this helps...
    regards,
    Stewart

  • SSRS,MDX- Passed parameters are not hitting the main query in Dataset

    I have created a SSRS report which has to accept two parameters i.e., store name, Date(to show sales on particular date) in report. which are working fine for me. but, those passed parameters are not hitting the main query in main Dataset. what ever i
    pass in parameters, it is displaying all the rows(every city values). i think i am not correct in creating the statement in  Main dataset query, to receive those 2 parameters into the main query. can anybody please help me how to create the statement
    in main date set to display the results for the exact parameter i am passing(which has to be in MDX).
    ram

    Hi ramprasad74,
    According to your description, you want to use parameter in the report, then after parameter values are selected, corresponding data will be displayed in the report. But the parameters do not work and all the rows are displayed.
    To pass parameter to main report dataset, we need to define parameter for MDX query and assign parameter name same as SSRS report parameter. For detail information, please refer to the following steps:
    Create a Dataset to retrieve data for Store name parameter.
    Create Store name parameter, type name and prompt, set Date type to Text, check Allow multiple values check box, then select get values from the dataset.
    Create a Dataset for Date parameter.
    Create Date parameter, type name and prompt, set Date type to Date/Time, then select get values from the dataset.
    Create a new dataset used to retrieve data for the report, add statement like below to the mdx query: {STRTOMEMBER(@Date)} * {STRTOSET (@Store_name)}.
    In Query Designer pane, click Query Parameters and assign parameter name same as SSRS report parameter.
    For more information about SSRS Report with Single and Multi Selection Parameter using MDX Query, please refer to the following blog:
    http://www.codeproject.com/Articles/799265/SSRS-Report-with-Single-and-Multi-Selection-Parame
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    If you have any feedback on our support, please click
    here.

  • How to put distinct in the query

    Hi all,
    How to put distinct in the query.I checked in RPD , Distinct supported is already available. I marked the distinct check box in advance option still then i'm not getting distinct in the query.
    any idea , please help...

    In the RPD i have join between base table and view .i'm selecting 2 columns one from base table and other from view . which gives cartesian product . to avoid that i want to put distinct . I'm not using any measure . I'm taking direct columns.
    I'm getting distinct keyword if i'm accessing the report directly . but when i'm accessing it from dashboard in the back end while preparing the query it's writing distinct but the actual query which is sending to db does not have distinct.
    ==================================================
    RqList distinct
    VW_SCNR_114000074_TA_DATA.Match Identifier as c1 GB,
    VW_SCNR_114000074_TA_DATA.Tot Trans Amt as c2 GB,
    VW_SCNR_114000074_TA_DATA.Tot Trans Ct as c3 GB,
    case when VW_SCNR_114000074_TA_DATA.Alert Quality Code = '1' then 'Productive' when VW_SCNR_114000074_TA_DATA.Alert Quality Code = '2' then 'Non Productive' else 'Indeterminate' end as c4 GB,
    VW_SCNR_114000074_TA_DATA.Batch Identifier as c5 GB
    DetailFilter: Alert TA Data.Run Id > 0 and Alert Scenarios.Scenario Name = 'ScnroName' and Alert TA Data.Batch Id > 0
    OrderBy: c4 desc
    =================================================
    -------------------- Sending query to database named KYC1.1DEV-179 (id: <<16315>>):
    select T353.BATCH_ID as c1,
    case when T353.QLTY_RTG_CD = '1' then 'Productive' when T353.QLTY_RTG_CD = '2' then 'Non Productive' else 'Indeterminate' end as c2,
    T353.TOT_TRXN_CT as c3,
    T353.TOT_TRXN_AM as c4,
    T353.BREAK_ID as c5,
    T117.SCNRO_NM as c6
    from
    KDD_SCNRO T117,
    KDD_TA_DATA T130,
    KDD_TSHLD_SET T171,
    VW_SCNR_114000074_TA_DATA T353
    where ( T117.SCNRO_ID = T130.SCNRO_ID and T117.SCNRO_ID = T171.SCNRO_ID and T130.SCNRO_ID = T171.SCNRO_ID and T130.SCNRO_ID = T353.SCNRO_ID and T130.TSHLD_SET_ID = T171.TSHLD_SET_ID and T171.SCNRO_ID = T353.SCNRO_ID and T171.TSHLD_SET_ID = T353.TSHLD_SET_ID and 0 < T130.BATCH_ID and 0 < T130.RUN_ID )

  • Using varchar record in SELECT query

    Hi, from a VARCHAR field I get the string ",1,2,3,4,5,6,".
    I wish to use it in a SELECT query like:
    SELECT * FROM TABLE WHERE ID IN (1,2,3,4,5,6)
    Is there a way to obtain this in a tsql query ?
    Thank you
    Stefano

    CREATE TABLE t1
     col1 INT NOT NULL PRIMARY KEY,
     col2 VARCHAR(50) NOT NULL
    INSERT INTO t1 VALUES (1,'10,11,12')
    INSERT INTO t1 VALUES (2,'13')
    INSERT INTO t1 VALUES (3,'14,15')
    CREATE TABLE t2
     col1 INT NOT NULL PRIMARY KEY,
     col2 VARCHAR(50) NOT NULL
    INSERT INTO t2 VALUES (10,'A')
    INSERT INTO t2 VALUES (11,'B')
    INSERT INTO t2 VALUES (12,'C')
    INSERT INTO t2 VALUES (13,'D')
    INSERT INTO t2 VALUES (14,'E')
    INSERT INTO t2 VALUES (15,'F')
    SELECT DISTINCT O.col1, O.col2
    FROM t1 T
       INNER JOIN t2 O
          ON (PATINDEX('%,' + CAST(O.col1 AS varchar(10)) + ',%',
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Using buffering option in select query

    Hi All,
           Can anybody give me a brief idea on , where we will use the buffering and how we will write it in coding part.Similarly please tell me what will happen if we use  by passing buffering  addition in select query. Please explain  it with steps of sample code if possible.
    Thanks in advance.
    Regards,
    Rakesh.

    Hi Sharma,
    Buffer is used to hold large amount of data.
    if internla table is unable to hold data.. Buffer is used..this is mainly used in copy data from PRD to Quality as a part testung.
    see the sample code how the buffer is used..
    FUNCTION zzrfc_get_zcpeg_fg_related.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(PL_VERSION) LIKE  ZCPEG_FG_RELATED-PL_VERSION OPTIONAL
    *"     VALUE(BYPASS_BUFFER) LIKE  SY-FTYPE DEFAULT SPACE
    *"     VALUE(FROM_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"     VALUE(GEN_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"     VALUE(MAX_ENTRIES) LIKE  SY-TABIX DEFAULT 0
    *"     VALUE(TABLE_NAME) LIKE  X030L-TABNAME
    *"     VALUE(TO_KEY) LIKE  SY-ENTRY DEFAULT SPACE
    *"  EXPORTING
    *"     VALUE(NUMBER_OF_ENTRIES) LIKE  SY-INDEX
    *"  TABLES
    *"      ENTRIES STRUCTURE  ZCPEG_FG_RELATED
    *"  EXCEPTIONS
    *"      INTERNAL_ERROR
    *"      TABLE_EMPTY
    *"      TABLE_NOT_FOUND
      TABLES dd02l.
      DATA: BEGIN OF buf OCCURS 100,
                line(4100),
            END OF buf.
      DATA keyln TYPE i.
      DATA: l_tabname LIKE dd25v-viewname.
      DATA: l_len     TYPE i.
      DATA : w_plversion TYPE /sapapo/vrsioex.   "PJONNALA
      w_plversion =  pl_version.                 "PJONNALA
      l_tabname = table_name.
      CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
        EXPORTING
          view_action                = 'S'
          view_name                  = l_tabname
          no_warning_for_clientindep = 'X'
        EXCEPTIONS
          OTHERS                     = 6.
      IF sy-subrc <> 0.
        RAISE internal_error.
      ENDIF.
      IF bypass_buffer NE ' ' AND bypass_buffer NE 'N'.
        bypass_buffer = 'Y'.
      ENDIF.
      IF gen_key CA ' '. ENDIF.
      keyln = sy-fdpos.
    * read client dependant tables always with client
      SELECT SINGLE * FROM dd02l WHERE tabname = table_name
                                  AND as4local =  'A'.
      IF dd02l-clidep = 'X'.
    *l_len = strlen( sy-mandt ) * cl_abap_char_utilities=>charsize.
    *  " ecwg. unicode
    *    move gen_key to gen_key+l_len.
    *    move sy-mandt to gen_key(l_len).
    *    add l_len to keyln.
        CONCATENATE sy-mandt gen_key INTO gen_key.
        keyln = STRLEN( gen_key ) * cl_abap_char_utilities=>charsize.
      ENDIF.
    *  endselect.
      IF keyln NE 0 OR from_key = space.
        CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                           ID 'INTTAB'    FIELD buf-*sys*
                           ID 'GENKEY'    FIELD gen_key
                           ID 'GENKEY_LN' FIELD keyln
                           ID 'DBCNT'     FIELD number_of_entries
                           ID 'BYPASS'    FIELD bypass_buffer.
      ELSE.
        CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                           ID 'INTTAB'    FIELD buf-*sys*
                           ID 'FROM_KEY'  FIELD from_key
                           ID 'TO_KEY'    FIELD to_key
                           ID 'DBCNT'     FIELD number_of_entries
                           ID 'BYPASS'    FIELD bypass_buffer.
      ENDIF.
      CASE sy-subrc.
        WHEN 4.  RAISE table_empty.
        WHEN 8.  RAISE table_not_found.
        WHEN 12. RAISE internal_error.
      ENDCASE.
      DESCRIBE TABLE buf LINES number_of_entries.
    ENDFUNCTION.
    Regards,
    Prabhudas

  • Addition of Command based Custom table removes 'Distinct' keyword in Query

    Hi,
    I use 'Command' Object in 'Datbase Expert' to create 'Custom Tables' and use these tables to fetch LoVs. Addition of 'Command' Object is changing the existing Query and the only change is 'Distinct' in the Query got eliminated and showing 210 recirds instead of Just 10. I did not link this Custom table with any of the tables. If I delete this again the query showing only distinct values eliminating duplicates. Please help.
    Edited by: Nanda Kishore B on Jul 16, 2010 12:36 PM

    Nanda,
    My guess would be that you've placed one of the fields from the LOV Command somewhere on your report. The fact that the LOV Command isn't linked to any of the other tables will cause CR to create a Cartesian join if any of the Command fields are used outside of the parameter's LOVs.
    HTH,
    Jason

  • Inner Query relating to calculated field in main query

    I have a query that has calculating fields in it.
    What I am trying to do is Create another inner SELECT query similar to the one above but using the FP_Qty_Required calculated field in the main query?
    Is this even possible?
    Thanks in advance
    Aaron

    Sorry.  I did that because it looked a mess when I pasted it in.
    SELECT        P.ItemNumber, P.DeliveryWeek, D.StartDate AS WC_Date, S.SumOfSchedule_Qty, P.Planned_Production_Qty, P.Actual_Production_Qty, D.StartDate,
                             CASE WHEN S.SumofPartPallet < 0 THEN 'PART PALLET' ELSE '' END AS PartPallet, S.FirstOfIntouchRef, S.Pallet_Qty,
    S.FirstOfTool_Number,
                             CAST(CASE WHEN S.SumOfSchedule_Qty > 0 THEN (S.SumOfSchedule_Qty - 1.0) / S.Pallet_Qty ELSE 0.00 END AS DECIMAL(18,
    2)) AS DecNoOfPallets,
                             CEILING(CAST(CASE WHEN S.SumOfSchedule_Qty > 0 THEN (S.SumOfSchedule_Qty - 1.0) / S.Pallet_Qty ELSE 0.00 END
    AS DECIMAL(18, 2))) AS QtyOfFullPallets,
                             CASE WHEN s.sumofpartpallet < 0 THEN s.sumofschedule_qty ELSE CEILING(CAST(CASE WHEN S.SumOfSchedule_Qty >
    0 THEN (S.SumOfSchedule_Qty - 1.0)
                             / S.Pallet_Qty ELSE 0.00 END AS DECIMAL(18, 2))) * s.pallet_qty END AS FP_Qty_Required,
                                 (SELECT        SUM(SumOfSchedule_Qty) AS Expr1
                                   FROM            dbo.SumOfSchedDelivery
    AS s2
                                   WHERE        (ItemNumber = S.ItemNumber)
    AND (DeliveryWeek <= S.DeliveryWeek)) AS Running_Sum,
    FROM            dbo.Production AS P INNER JOIN
                             dbo.SumOfSchedDelivery AS S ON P.ItemNumber = S.ItemNumber AND P.DeliveryWeek = S.DeliveryWeek INNER JOIN
                             barcoding.dbo.DeliveryWeeks AS D ON P.DeliveryWeek = D.DeliveryWeek INNER JOIN
                             dbo.TotalRequiredByItem AS T ON S.ItemNumber = T.ItemNumber
    The above works.  What I want to do next is after the Running_Sum to add another sub query similar to this:
    (SELECT        SUM(FP_Qty_Required) AS Expr2
                                   FROM            ???
                                   WHERE        (PD.ItemNumber = ItemNumber)
    AND (PD.DeliveryWeek >= DeliveryWeek)) AS Running_FullPallet
    FP_Qty_Required is a calculated field in the main query.

  • Issue with join condition while using in the corelated sub query

    Bees,
    I am not able to use the below query since i have used a join condition in the corelated sub qery inline view.But i have a requirement like this . Please help me on this
    select * from dept d
    where exists (select 1 from (
    select deptno
    from emp where deptno= d.deptno)
    Thank you
    Boooo

    Hi,
    I've never seen a general solution for how to reference columns from main query a from sub-query c, where c is is sub-query of b, which is a sub-query of a.
    Whenever I've wanted to, I've been able to get the desired results with a different approach.
    In this case, you seem to want
    SELECT     *
    FROM     dept     d
    WHERE     EXISTS     (
              SELECT     1
              FROM     emp
              WHERE     deptno     = d.deptno
              );I'm guessing at your data and desired output.

  • DISTINCT in the query -- RBO vs CBO

    Hi all,
    We are in a process of migrating our applications from RBO to CBO as we moved to 10g and recently I observed a simple query with DISTINCT clause showing different results in CBO. Here is my order of creating a table in 10g environment,
    create table m_test(col1 varchar2(3));
    insert into m_test values('ZYT');
    insert into m_test values('ABC');
    insert into m_test values('RKT');
    select * from m_test
    col1
    ZYT
    ABC
    RKT
    alter session set optimizer_mode = RULE
    select distinct col1 from m_test;
    col1
    ABC
    RKT
    ZYT
    Note: Explain plan shows that it's doing SORT UNIQUE
    alter session set optimizer_mode = FIRST_ROWS_1
    select distinct col1 from m_test;
    col1
    ZYT
    ABC
    RKT
    Note: Explain plan shows that it's doing HASH UNIQUE
    I would appreciate if someone can let me know why this is happening,
    Thank you,
    Madhu

    It happened to be sorted when you were using the RBO because the query plan the RBO generated happened to involve a sort. The CBO knows that sorting isn't strictly necessary, so it may or may not choose to apply the sort.
    The CBO has a lot of options for generating query plans, depending on table, column, index, and system statistics, histograms, etc. and has a lot more plan options than the old RBO did. The CBO is a lot more likely to change a query plan than the RBO was, which is normally a good thing (a plan that works for a 10 row table might need to be changed if the table grows to 1 million rows). Depending on the Oracle version, initialization parameters, table statistics, system statistics, etc. the CBO may happen to sort rows before returning them.
    If you want Oracle to sort the rows, however, there is only one way to guarantee that-- add an ORDER BY clause.
    Justin

  • Can I use table function inside Dynamic query ?

    Dear Gurus,
    I have following code
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
              'CAST (OtherNoList AS CRITERIA_LIST_TABLE) '||
                   ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING;
    END;
    Can I use Table function inside dynamic query.
    Thanking in advance
    Sanjeev

    Try:
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
    'CAST (:OtherNoList AS CRITERIA_LIST_TABLE) '||
    ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING using OtherNoList;
    END;p.s. not tested
    Amiel Davis

  • How will get subquery return multiple values and passing to the main query

    Hi all ;
    here i given one sql query
    1)select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '|| initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
    b.name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
    from table1 a
    join table3 c on c.emptype = a.emptype
    left outer join table2 b on a.name = b.name
    where a.mgrid = 100;
    if i run this above query returning multiple values depend on sa.mgr values.
    like output coming like this
    [yes]:2000-anbarasan
    [yes]:2700-anb
    [yes]:2000-rasan
    [yes]:2807-anbarasan
    [yes]:2700-anbanu
    [yes]:2000-null
    2) this sub query i am passing with main query
    select sa.mgrid,sa.sal,(select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '||
    initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
    b .name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
    from table1 a
    join table3 c on c.emptype = a.emptype
    left outer join table2 b on a.name = b.name
    where a.mgrid = 100)" test " from table4 sa,table5 te ,table6 ft where sa.id(+)=te.id and sa.mgr=ft.mgr;
    my final out put required like this:
    mgrid sal test
    100 20000 [yes]:2000-anbarasan
    [yes]:2700-anb
    [yes]:2000-rasan
    [yes]:2807-anbarasan
    [yes]:2700-anbanu
    [yes]:2000-null
    but i am getting erro:
    1)missing paranths-it solved
    2)single row subquery return more then one row.
    give me the correct solution.how will solve this problem
    Edited by: anbarasan on Sep 29, 2008 6:49 AM
    Edited by: anbarasan on Sep 29, 2008 6:51 AM
    Edited by: anbarasan on Sep 29, 2008 6:53 AM
    Edited by: anbarasan on Sep 29, 2008 6:56 AM
    Edited by: anbarasan on Sep 29, 2008 6:58 AM

    Hi,
    It doesn't look like you posted either the complete query or the complete error message (including line number). Try again.
    "single row subquery return more then one row" usually means you are using a sub-query in a place where a single expression is expected, for example the column called avg_sal in this query:
    SELECT  ename
    ,       sal
    ,       (SELECT  AVG (sal) FROM scott.dept WHERE deptno = e.deptno) AS avg_sal  -- Scalar-sub-query
    FROM    scott.emp  e; The error occurs when the sub-query returns more than one row
    If the sub-querry really is supoosed to be returning only one row, the solution is to fix the sub-query, usually be adding something to the WHERE clause.
    If the sub-query is supposed to return more than one row, then the main query has to be re-written, perhaps as a join.
    Post a little sample data and the results you want from that data if you need help.

  • Count distinct within a query

    Hi there,
    I have a below query that has a count field, which I want to have count of unique records.
    SELECT [SGMT_REV_BY_SITE].GLSeq, Count([SGMT_REV_BY_SITE].SITE_ADDR_ID) AS NUM_SITES, [SGMT_REV_BY_SITE].SGMNT1, [SGMT_REV_BY_SITE].SGMNT2, [SGMT_REV_BY_SITE].LOB$, [SGMT_REV_BY_SITE].PERIOD, [SGMT_REV_BY_SITE].RECUR, [SGMT_REV_BY_SITE].PROMOTED, Sum([SGMT_REV_BY_SITE].REV_GRS)
    AS REV_GRS_Sum, Sum([SGMT_REV_BY_SITE].REV_NET) AS REV_NET_Sum, IIf(NUM_SITES >0, REV_GRS_Sum/NUM_SITES, REV_GRS_Sum) AS ARPSg_Sum, IIf(NUM_SITES >0, 
    REV_NET_Sum/NUM_SITES, REV_NET_Sum) AS ARPSn_Sum
    FROM SGMT_REV_BY_SITE
    WHERE ([SGMT_REV_BY_SITE].SGMNT1="Small"
    Or [SGMT_REV_BY_SITE].SGMNT1="Medium")
    And [SGMT_REV_BY_SITE].PERIOD>#12/31/2013#
    And [SGMT_REV_BY_SITE].RECUR=Yes
    And [SGMT_REV_BY_SITE].PROMOTED=Yes
    And [SGMT_REV_BY_SITE].REV_NET<>0
    GROUP BY [SGMT_REV_BY_SITE].GLSeq, [SGMT_REV_BY_SITE].LOB$, [SGMT_REV_BY_SITE].SGMNT1, [SGMT_REV_BY_SITE].SGMNT2, [SGMT_REV_BY_SITE].PERIOD, [SGMT_REV_BY_SITE].RECUR, [SGMT_REV_BY_SITE].PROMOTED;
    Is there an easy way of accomplishing the task.
    Thanks in advance for help.

    ARSagit,
    Unfortunatly access don't support count(distinct fieldname) statement...
    Workaround is:
    SELECT [NS].glseq,
    Count([NS].site_addr_id) AS NUM_SITES,
    [NS].sgmnt1,
    [NS].sgmnt2,
    [NS].lob$,
    [NS].period,
    [NS].recur,
    [NS].promoted,
    FROM (
    SELECT DISTINCT
    [sgmt_rev_by_site].glseq,
    [sgmt_rev_by_site].site_addr_id
    [sgmt_rev_by_site].sgmnt1,
    [sgmt_rev_by_site].sgmnt2,
    [sgmt_rev_by_site].lob$,
    [sgmt_rev_by_site].period,
    [sgmt_rev_by_site].recur,
    [sgmt_rev_by_site].promoted,
    FROM
    sgmt_rev_by_site
    WHERE [sgmt_rev_by_site].sgmnt1 in ("small","medium")
    AND [sgmt_rev_by_site].period >#12/31/2013#
    AND [sgmt_rev_by_site].recur = yes
    AND [sgmt_rev_by_site].promoted = yes
    AND [sgmt_rev_by_site].rev_net <>0) AS NS
    GROUP BY [NS].glseq,
    [NS].lob$,
    [NS].sgmnt1,
    [NS].sgmnt2,
    [NS].period,
    [NS].recur,
    [NS].promoted;
    With this quer you can join with main query and show num_sites....
    Michał

  • Check Index used in an oracle select query

    Hi Friends,
    I have partitioned an oracle table and created Local Index for the Partitioned table .
    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?
    Please let me know.
    Regards,
    DB

    Now i want to make sure that the Local index is being used when i perform select query on the Table partition.Why? Have you proven that using this local index is the "best" plan?
    How do i confirm that ?
    can i check the explain plan generted for the select query to confirm local index is being used ?When I asked Google "how to read an oracle explain plan," I found lots of information - what did you find?

Maybe you are looking for

  • MacBook Pro Retina SMC Update 1.1 Won't Install

    Hi Everybody. I am having a really annoying problem with my rMBP. I have the update labaled: "MacBook Pro Retina SMC Update 1.1" Available in my Mac AppStore app. After I click update, I get a prompt letting me know that the laptop needs to be plugge

  • HELP.  Upgraded to 10.6.8 and now pics messed up!!

    Hi, was happy with my old imac (really old - 7 years, 75 lines of pixels-but trying to get more life out of it) but hubby insisted i need to upgrade to snow leopard.  so now i am at 10.6.8   (2ghz intel, cor 2 duo, 1gb 667mhz, ddr2, sdram)      my ip

  • Open EXR Channel Caching Options Broken?

    Hi! It's been awhile! Nice to be back on the ole' stomping grounds! I'm a bit confused as to where the Open EXR channel caching functionality has gone. If I select my 32-bit Open EXR sequence in the project window and choose to interpret it, when I c

  • TIP: Working with AVCHD while ingesting

    You can do this. If you have a long list of clips to ingest from an AVCHD chip or drive, you can start the ingest process, and while it's going on in the background, begin cutting up your clips organzing your browser, and editing the already ingested

  • Cannot drag & drop clip in Home Video of itune 11.1.3.8

    It has been a few months since I last drop video clip onto the itune and then transfer it to my iphone by clicking the Sync button. Today, when I tried to drop more clips into my Home Videos under the Movies to transfer to my iphone, I NO LONGER able