Select distinct record based on column

Hello All,
I have a table that has more than one row as Detail for a single invoice number(screenshot below). When I create report based on this table, I get multiple rows for single invoice. I mean Invoice 000027 shows up with 5 different rows on the SSRS report.
Is there a way I could display a single row for a single invoice? Any thoughts on this will be greatly appreciated. Thanks.
Regards,
Amol
eport )

Thank you all for your suggestions. The issue is how can I get single distinct columns after joining 2 tables (InvoiceHeader & InvoiceDetail). I am using following query in my dataset.
SELECT DISTINCT I.recid, I.InvNumber, D.Detail, I.CompanyName, I.Addr1, I.SalesRep, I.JobNumber, I.Status, I.InvDate, I.TotalInvAmount
FROM            InvoiceHeader AS I INNER JOIN
                         InvoiceDetails AS D ON I.InvNumber = D.InvoiceNumber
WHERE        (I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) OR
                         (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) OR
                         (I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) 
                         AND (@JobNo = '') OR
                         (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) AND 
                         (@JobNo = '') OR
                         (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (@JobNo = '') AND 
                         (@InvoiceNumber = '')
ORDER BY I.InvNumber DESC
Thanks again.
Amol

Similar Messages

  • How can I select random records from one column

    How can I random select 400 records from a column contains more than 500,000 records? And how long will it take in oracle? Thanks.

    here is one option: (just change 5 to suit your needs...)
    SQL>select * from (
      2  select object_name
      3  from all_objects
      4  order by dbms_random.random
      5  ) where rownum < 5
      6  /
    OBJECT_NAME
    UTL_SYS_COMPRESS
    GV_$LOG_HISTORY
    GV_$LOGMNR_LOGS
    WWV_FLOW_THEME_7
    SQL>/
    OBJECT_NAME
    WWV_FLOW_UPGRADE_REPORT
    WRI$_ADV_SQLT_STATISTICS_PK
    V_$DATABASE
    GV_$SERVICEMETRIC
    SQL>/
    OBJECT_NAME
    WWV_FLOW_CREATE_FLOW_API
    WRH$_SERVICE_WAIT_CLASS_BL
    EXU8SNAPL
    GV$SERVICEMETRIC_HISTORY
    SQL>                well, regarding how long will it take... it depends from lots of variables...
    Cheers,
    Andrea

  • "Select Distinct Records" Option Not Available

    Hello Experts.
    I am working on a new report in CR XI, and noticed that I had many duplicate records.  I went to the File; Report Options; and expected to click on "Select Distinct Records", but that choice was grayed-out.  What would have caused me to lose this option, and how do I fix it?
    Thanks in advance for your help.

    Not sure if this covers it or not, but....
    The Select Distinct Records command is only available for ODBC, OLE DB, and SQL native drivers; it is not available for Stored Procedures. Note also that your server may automatically sort returned values if no sort is specified in Crystal Reports.

  • Best way to select distinct values based on another column?

    I have a table with three columns: id (NUMBER), data_dt (DATE), and data_value (NUMBER).
    There is a primary key on id and data_dt.
    I want to select the record with the latest data_dt for each unique id.
    What is the best way to do this?
    I have three different methods, but there may be something I am missing.
    First:
    SELECT *
    FROM
      SELECT id, data_dt, data_value,
             FIRST_VALUE(data_dt)
             OVER (PARTITION BY id ORDER BY data_dt DESC) AS last_data_dt
      FROM the_table
    WHERE data_dt = last_data_dt;(I use ORDER BY...DESC instead of just ORDER BY so I don't need the ROWS BETWEEN clause)
    Second:
    SELECT t1.*
    FROM the_table t1
    JOIN
      SELECT id, MAX(data_dt) AS last_data_dt
      FROM the_table
      GROUP BY id
    ) t2 ON (t2.id = t1.id AND t2.data_dt = t1.data_dt);Third:
    SELECT t1.*
    FROM the_table t1
    WHERE t1.data_dt =
      SELECT MAX(t2.data_dt)
      FROM the_table t2
      WHERE t2.id = t1.id
    );-- Don

    Hi,
    There are more possible scenario's, for example:
    select t1.*
    from   the_table t1
    where not exists ( select null
                       from   the_table t2
                       and    t2.data_dt > t1.data_dt
    What is the best way to do this?Only you can tell:
    Test all scenario's, check the execution plans, set timing on and pick the best/fastest one ;-)
    If it's not clear, please post the execution plans here.

  • Formula to select first record on the column

    Hi All
    I need a formula to select a first record on the column, here is my query
    SELECT DISTINCT
                          dbo.OWOR.DocNum, dbo.OWOR.ItemCode, dbo.OWOR.Status, dbo.OWOR.PlannedQty, dbo.ITM1.Price, dbo.OWOR.Warehouse,
                          dbo.OWOR.PlannedQty * dbo.ITM1.Price AS Total
    FROM         dbo.OWOR INNER JOIN
                          dbo.ITM1 ON dbo.OWOR.ItemCode = dbo.ITM1.ItemCode
    WHERE     (dbo.OWOR.Status = 'P') OR
                          (dbo.OWOR.Status = 'R') AND dbo.ITM1.Price
    I need to select the first price on the price list for (dbo.ITM1.Price).
    Regards
    Bongani

    Bongani,
    Are you sure you don't want to link a pricelist? Because the unique key on ITM1 consists of ItemCode and PriceList and taking the first price for an item in ITM1 could result in kind of random prices for different items, depending on whice pricelist gets filled first for a certain item.

  • Select distinct records in Mapping with no Key field (all fields can vary)

    Hi Experts,
    Let me take an example (not the actual requirement but same scenario) to explain the problem where I need your help to get best possible way to resolve. This has to be achieved in mapping, don't have other options as its part of complex end 2 end scenario.
    I have following input XML:
    <Employee>
       <Details>
          <Id>123</Id>
          <Name>ABC</Name>
         <Role>Manager</Role>
          <Area>Bangalore</Area>
        </Details>
        <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Pune</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Advisor</Role>
             <Area>Bangalore</Area>
         </Details>
          <Details>
           <Id>123</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
           <Details>
           <Id>143</Id>
           <Name>ABC</Name>
            <Role>Manager</Role>
             <Area>Bangalore</Area>
         </Details>
    </Employee>
    The output XML is:
    <Employee>
       <MainRec>
           <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Manager</Role>
                            <Area>Pune</Area>
                      </record>
                      <record>
                          <Id>123</Id>
                           <Role>Advisor</Role>
                            <Area>Bangalore</Area>
                      </record>
                  </table>
          </MainRec>
          <MainRec>
            <Id>123</Id>
            <Name>ABC</Name>
             <table name = 'Roles'>
                   <record>
                          <Id>143</Id>
                           <Role>Manager</Role>
                            <Area>Bangalore</Area>
                      </record>
                </table>
            </MainRec>
    </Employee>
    As you can see from the example above, here I want to populate only distinct records under table, but there is no key fiield to ditunguish. Any of the 3 fields (Id, Role,Area) can vary and between 2 records if all of these fields are same then its duplicate else select it. So in above XML just discard the 4th record from the source XML and populate all others. Each record has to be checked against all other records all 3 values (ID, Role, Area). Only when none of the records have exactly the same values, populate it.
    Also records with different ID come under different table node. Hope my requirement is clear, if not please let me know, i will try to explain better.
    I thought of creating a UDF to achieve this but not able to decide how to match it to the output message here.
    Best Regards,
    Pratik

    Hi,
    For the main record, I think you only need to check for each unique ID, e.g
    Id --> removeContext --> sort:ascending --> splitByValue:valueChanged --> collapseContext --> MainRec
    For the record, however, you need to create a UDF that will filter out the duplicate values. For this, the UDF sample mentioned here contained multipleResult lists
    Id --> removeContext --> concat: : --> concat: : --> UDF --> splitByValue:ValueChanged --> record
    role --> removeContext --> /          /                \ --> Id
    area --> removContext -------------> /                  \ --> role
                                                             \ --> area
    Context type UDF
    Arguments: input
    Result: IdResult
    Result: roleResult
    Result: areaResult
    Vector temp = new Vector();
    for(int a=0;a<input.length;a++){
       if(!temp.contains(input[a])
             temp.add(input[a]);
    for(int a=0;a<temp.size();a++){
       String tmp = (String) temp.get(a);
       /*split according to field */
       IdResult.addValue(tmp.substring(0,tmp.indexOf(":")));
       roleResult.addValue(tmp.substring(tmp.indexOf(":")+1,tmp.lastIndexOf(":")));
       areaResult.addValue(tmp.substring(tmp.lastIndexOf(":")+1,tmp.length()));
    note: Id and record will both be using the IdResult list.
    Hope this helps,
    Mark

  • Select distinct for a date column in present. service when creating prompt

    hi all
    I am trying to create some new prompts in my answers and I have the following problem. When I try to create a new prompt on a date column ( for example Modification Date), when I try to run this report on this prompt it is displaying the same date a lot of times ( for example 2/4/11 it is being displayed 4 times).
    Is there any way i can change this, so to display distinct dates?
    Thank you and best regards

    Hi Deva
    I am trying to use this, but in the system are being saved the date + hour.
    When i try select distinct modification date from My_view, i still have the same dates because they have different hours.
    When i try select disctinct to_date(modification_date)..... I am having an error in BI.
    Please help me to solve this issue.
    Regards

  • Select distinct records without using distinct

    hi experts,
    my retrieved data like these:
    cnt_id cnt_type rcrd_id wrkflw_id
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248
    now i want to select one record for each cnt_id without using any distinct function .. how can i do that?
    regards,
    SKP

    you can use the below query
    select * from t where rowid in (select max(rowid)
    from t group by cnt_id)You're query is not the equivalent of DISTINCT.
    SQL> ed
    Wrote file afiedt.buf
      1  create table t as
      2            (select 558848 as cnt_id, 'PRODUCT' as cnt_type, 553503 as rcrd_id, 248 as wrkflw_id from dual union all
      3             select 558848, 'RETURN', 553503, 248 from dual union all
      4             select 558848, 'PRODUCT', 553503, 248 from dual union all
      5             select 558808, 'PRODUCT', 553463, 248 from dual union all
      6             select 558808, 'PRODUCT', 553463, 248 from dual union all
      7             select 558808, 'PRODUCT', 553463, 248 from dual union all
      8             select 558810, 'PRODUCT', 553463, 248 from dual union all
      9             select 558810, 'PRODUCT', 553463, 248 from dual union all
    10*            select 558810, 'PRODUCT', 553463, 248 from dual)
    11  /
    Table created.
    Elapsed: 00:00:00.01
    SQL> select * from t where rowid in (select max(rowid) from t group by cnt_id);
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL> select distinct * from t;
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 RETURN      553503        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL>

  • Select distinct('more than one column') from ....

    Why does this sql statement not work:
    select distinct(column_a, column_b, column_c), empno
    from emp;
    How can I 'select distinct' using more than one column.

    Actually, DISTINCT applies to all columns in the result.
    Distinct is not a function, you cannot do distinct(column1, column2, ...).
    As a matter of fact it doesn't make sense to expect distinct applies to only one column, because you do not specify any criteria on how to select the values for the second column.
    A final note: you can do distinct(column1), column2, but this will still apply to both columns!
    Here're some examples that will all return both rows from the set, where set is: (1,1), (1,2):
    select distinct val1, val2
    from
    select 1 as val1, 1 as val2 from dual
    union all
    select 1 as val1, 2 as val2 from dual
    select distinct val1||'-'||val2
    from
    select 1 as val1, 1 as val2 from dual
    union all
    select 1 as val1, 2 as val2 from dual
    select distinct(val1), val2 -- this is very misleading. distinct still applies to both columns
    from
    select 1 as val1, 1 as val2 from dual
    union all
    select 1 as val1, 2 as val2 from dual
    Edited by: user4010726 on Dec 1, 2009 11:06 AM
    Edited by: user4010726 on Dec 1, 2009 11:07 AM

  • Select Distinct (More than one column)

    Hi All,
    I have the following SQL statement written in MySQL that returns only one row per MODCODE with the associated DEPTCODE of AE:
    SELECT DISTINCT
    EL_MODULE.DEPTCODE, EL_MODULE.MODCODE, EL_MODULE.MODNAME, EL_MODULE.MODLEVEL, EL_DEPTLEVEL.DEPTLEVELHEADER
    FROM EL_DEPTLEVEL, EL_MODULE
    WHERE EL_MODULE.MODLEVEL = EL_DEPTLEVEL.LEVELCODE AND EL_MODULE.DEPTCODE='AE' ORDER BY EL_MODULE.MODLEVEL
    However when I attempt to use this in oracle it returns three rows, could somebody point out what it is I need to change to get this working correctly in oracle.
    Hope someone can help.
    Jon

    Duplicates? No way! This query returns unique comibination of
    EL_MODULE.DEPTCODE,
    EL_MODULE.MODCODE,
    EL_MODULE.MODNAME,
    EL_MODULE.MODLEVEL and
    EL_DEPTLEVEL.DEPTLEVELHEADER
    Cheers
    Sarma.

  • Select distinct records in query

    If I want to read a table in an infoset, how can I just select distinct entries from the table?
    Is it done at the infoset level or the query level?

    I've actually created the infoset for table VBFA and created a query.
    But I can't limit the output such that for each DO, show only distinct subsequent Invoice.
    eg. DO 123 has 3 items, and this DO 123 has only 1 Invoice 456, then in the output, there will be
    DO    |     Invoice
    123   |     456
    123   |     456
    123   |     456
    It's repeated 3 times because there are 3 items in VBFA for this DO. How can I create the infoset/query so that the output will be 1 entry only, ie
    DO    |     Invoice
    123   |     456
    Thanks

  • Distinct records based on condition within a table

    Hello PL/SQL Gurus/experts,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
    I have following table -
    Note - Table don't have any primary key on Order_ID -
    DROP TABLE T;
    create table T(Order_ID,Active_Flg) as select
    '201002', 'Y' from dual union all select
    '201002', '' from DUAL union all select
    '201003', '' from dual union all select
    '201004', 'Y' from DUAL union all select
    '201004', '' from dual union all select
    '201005', '' from DUAL ;I want to fetch those Order_ID which have Active-Flg as NULL and don't have the entry for Active_Flg=Y
    If use the following then it returns the distinct Order_ID but not the expected one -
    SELECT DISTINCT ORDER_ID FROM T WHERE ACTIVE_FLG IS NULL;Result -
    ORDER_ID
    201004
    201002
    201003
    201005Kindly help.....

    try this
    with t as
    select
    '201002' order_id, 'Y' active_flg from dual union all select
    '201002', '' from DUAL union all select
    '201003', '' from dual union all select
    '201004', 'Y' from DUAL union all select
    '201004', '' from dual union all select
    '201005', '' from DUAL
    select order_id
      from (
              select
                order_id,
                active_flg,
                count(case when active_flg =  'Y' then 1 end) over(partition by order_id) cntY
              from t
    where cntY = 0 and active_flg is null

  • Select Distinct records

    Hi..
    I'm getting error when trying to fill the combo using select with distinct command....i have duplicate records but recordset is not working with distinct command....
    Thanks..

    Hi Pari,
    you can solve this using GROUP By
    Select U_ELCategoryCode,U_ELCategoryName from [@ENTITLEMENTCATEGORY]
    group by U_ELCategoryCode,U_ELCategoryName
    that will remove records where U_ELCategoryCode and U_ELCategoryName are the same.
    lg David

  • Dynamic selection of records based on checkbox checked

    Hello,
    I want to select a list of records from a multirecord block by
    using the checkbox checked values as the criterion and use the
    records selected in the where clause for querying in another
    forms. The data from the multirecord block is from a query
    result and hence is dynamic.
    I went about doing this:
    I created a multirecord block. In the multirecord block, I
    created a checkbox which was a non-database item.
    In the when_button_pressed trigger I wrote the following code:
    declare
         temp varchar2(1000);
         start_rec number;
         stop_rec number;
         item_id item;
         block_id block;
         item_value varchar2(1000);
         pl_id paramlist;
         item_name varchar2(10);
         patient_list varchar2(1000);
    begin
    go_block('patient_list');
    block_id:=find_block('patient_list');
    start_rec:=1;
    stop_rec:=get_block_property(block_id,query_hits);
    for i in start_rec..stop_rec loop
    if :selection='Y' then --selection is the checkbox           
         if item_value is null then
    /*item_value holds the value of the data shown in the forms &
    for which the checkbox is checked*/
    item_value:=name_in(':patient_list.patient_id');
    /*patient_id is the item name as well as field name in the
    table*/
         else
    item_value:=item_value||','||name_in(':patient_list.patient_id');
         end if;
    end if;
    end loop;
    patient_list:='('||item_value||')';
    pl_id:=create_parameter_list('list_of_patients');
    add_parameter(pl_id,'querypatients',text_parameter,patient_list);
    message(patientlist);
    run_product
    (forms,'patient_history',synchronous,runtime,filesystem,pl_id,nul
    l);
    end;
    When I run this form, patient_list comes as
    (111,111,111,111,111,111,111) where
    111 is the value of the patient_id.
    The only value that gets into the patient_list is the patient_id
    for the last checkbox I have
    checked in the forms and the same patient_id appears so many
    times.
    Can anyone tell me where I am doing the mistake? Why is the same
    value appearing so many times and only the last record selected
    appears in the patient_list.
    Thank you for your suggestions.

    Thank You.
    I added go_record(start_rec) and next_record and everything
    worked fine.
    Here I have the working code:
    declare
         temp varchar2(1000);
         start_rec number;
         stop_rec number;
         item_id item;
         block_id block;
         item_value varchar2(1000);
         pl_id paramlist;
         item_name varchar2(10);
         patient_list varchar2(1000);
    begin
         go_block('patient_list');
         block_id:=find_block('patient_list');
         start_rec:=1;
         stop_rec:=get_block_property(block_id,query_hits);
    go_record(start_rec);-- I added it
         for i in start_rec..stop_rec loop
         if :selection='Y' then --selection is the checkbox in  
    the patient_list block.
         if item_value is null then
    -- item_value holds the value of the data shown in the forms and
    for which the checkbox is checked
         item_value:=name_in(':patient_list.patient_id');
    -- patient_id is the item name as well as field name in the table
         else
         item_value:=item_value||','||name_in
    (':patient_list.patient_id');
         end if;
         end if;
    next_record;-- I added it
         end loop;
    patient_list:='('||item_value||')';
    pl_id:=create_parameter_list('list_of_patients');
    add_parameter(pl_id,'querypatients',text_parameter,patient_list);
    message(patientlist);
    run_product
    (forms,'patient_history',synchronous,runtime,filesystem,pl_id,nul
    l);
    end;

  • Selection of records based on minimum date actioned

    Post Author: jrdoyle
    CA Forum: Data Connectivity and SQL
    Hi!
    I've been building a report that displays records, grouped by the Service Department  to which they have been assigned; however I need to constrain the report to only show the Service Department to which the record was first assigned.  I had tried to group the report by incident reference #, and had in the details the actions taken agains the record, the date of the action, the SVD to which it was assigned, etc.  In the Select Expert, I have the following:
    {INC_DATA.EVENT_TYPE} = "i" and{SERV_DEPT.SERV_DEPT_SC} = "DISPATCH" and{INCIDENT.DATE_LOGGED} in DateTime (2007, 05, 01, 00, 00, 00) to DateTime (2007, 05, 30, 00, 00, 00) and{SERV_DEPT_1.SERV_DEPT_SC} in &#91;"CUSTHOME", "CUSTWEST", "HARDWARE"&#93;
    The SERV_DEPT_1 table will displays the information about the Service Department to which the records are assigned.  I need to be able to count only the minimum date of assignment.  I've tried using the Minimum function, but it appears that I then can't summarize (count records) higher up in the report groups, as it gets evaluated after (?) the groups are made.
    Is anyone able to offer suggestions as to how I might go about this?  I have tried to somehow flag records in the details which meet the criteria, but haven't been able to come up with anything yet.
    Thanks!

    Post Author: Jagan
    CA Forum: Data Connectivity and SQL
    I'm not quite sure how/where you tried to use the Minimum function - sounds like you used it in the record selection formula? Anyway, if you want the report to have only the earliest record per service department group then you can use the group selection expert, e.g.{incident.date_logged} = minimum({incident.date_logged}, {serv_dept_1.serv_dept_sc})If you want to display the earliest record but still have the other records there for processing then sort on {incident.date_logged} ascending, suppress the details, and print in the {serv_dept_1.serv_dept_sc} group header. i.e the record you're "looking" at in the group header is the first one for the group.The difference between the two is that the former will only have one record per service department group (assuming the date_logged is unique per incident per department) while the latter will have all records but only display one. This makes a difference when using the built-in summary functions.

Maybe you are looking for

  • Unable to Create a Simple LOV

    I am trying to create a simple LOV, but I keep getting the 'LOV query is invalid, a display and a return value are needed, the column names need to be different' error. This is my query: SELECT evaluation d, evaluation r FROM GRT_PRJ_EVALUATIONS WHER

  • Acrobat Reader 11.0.9 has never started

    Hi ! Today after the closing of a pdf document with Acrobat Reader X, I received an offer to install Acrobat Reader XI. The installation didn't report any problem. When i click on the freshly installed icon, I see a window for about 1 second. It alwa

  • Creating Space after a Paragraph Style

    Okay, all, this may sound weird. All I want to do in CS4 is have an extra 4 pt of space after a particular paragraph style. Specifically, my paragraph style, Body Text, already has "space after" specified at 3 pt. Fine. But, for example, when I have

  • Odd iPhone Calendar Behavior With CSV Calendar Dates After 3.1

    In April I downloaded the Chicago Cubs schedule as a CSV file and imported it into Outlook. The dates synced to my (and my wife's) 3G phones via MobileMe and we were good to go. Yesterday I did the same with the Chicago Bears schedule, and just notic

  • Practices for maintaining source code patches for branch of OSS project?

    There is this open source project I use and modify for my personal, private use... I would like some best-practice/practical experience suggestions on methodology/tools to maintain a growing number of source code patches I have created for said softw