Query to find duplicate referance numbers

Dear,
We have somehow managed to create the same sales order twice or more. In the field "Customer Ref. No." we always type in BP's ref. no. So what I need is a query which will show me all open sales orders which have more than one identical "Customer Ref. No." (ORDR.NumAtCard)
So what I got so far is:
SELECT T0.[DocNum], T0.[NumAtCard] FROM ORDR T0 WHERE T0.[DocStatus] <> 'C' AND ????
Hope anyone can help. Thanks.
BR
Kjetil Sandvik

Hi Kjetil Sandvik,
If you want to block Sales Order with duplicare Customer Ref. No then
Try this SP.....
if (@object_type = '17')
and (@transaction_type= 'A' or @transaction_type= 'U')
begin
declare @Refno as varchar(100), @Cust as varchar(100)
if @object_type = '17'
begin
select @Refno = NumAtCard,
@Cust=CardCode
from ordr
where DocEntry =@list_of_cols_val_tab_del
if 1 != (select count(DocEntry) from ordr with(nolock) where NumAtCard = @Refno and CardCode=@Cust)
begin
select @error = 1
select @error_message = 'Customer Ref. No Should Not Be Repeated. ! '
end
end
end
Thanks,
Srujal Patel

Similar Messages

  • Query to find duplicate datas

    Hi,
    can any one help me the query to find the duplicate data from a column.

    maybe this example might be of some help.
    SQL> select * from employees;
    YEAR EM NAME       PO
    2001 04 Sarah      02
    2001 05 Susie      06
    2001 02 Scott      91
    2001 02 Scott      01
    2001 02 Scott      07
    2001 03 Tom        81
    2001 03 Tom        84
    2001 03 Tom        87
    8 rows selected.
    SQL> -- based on the output above we know that there is duplicates on scott and tom
    SQL> -- now we need to identified how many are duplicates by grouping into year, empcode, and name
    SQL> select year, empcode, name, position,
      2         row_number() over (partition by year, empcode, name
      3                            order by year, empcode, name, position) as rn,
      4         count(*) over (partition by year, empcode, name) as cnt
      5   from employees;
    YEAR EM NAME       PO         RN        CNT
    2001 02 Scott      01          1          3
    2001 02 Scott      07          2          3
    2001 02 Scott      91          3          3
    2001 03 Tom        81          1          3
    2001 03 Tom        84          2          3
    2001 03 Tom        87          3          3
    2001 04 Sarah      02          1          1
    2001 05 Susie      06          1          1
    8 rows selected.
    SQL> -- we have identified the duplicates on the above outputs by the counts
    SQL> -- now we want to query only rows that has duplicates
    SQL> select emp.year, emp.empcode, emp.name, emp.position, emp.cnt
      2    from (select year, empcode, name, position,
      3                 row_number() over (partition by year, empcode, name
      4                                    order by year, empcode, name, position) as rn,
      5                 count(*) over (partition by year, empcode, name) as cnt
      6            from employees) emp
      7   where rn = 1
      8     and cnt > 1;
    YEAR EM NAME       PO        CNT
    2001 02 Scott      01          3
    2001 03 Tom        81          3
    SQL>

  • Query to find duplicate lows

    Dear all,
    i have a table
    create table attendance(dept_id number,att_date date,att_kind);
    all the three columns i want to put as a primary key,
    there is a data in the table.
    how would i check through a query that the table has duplicate values or not?
    in other words , i want to query just the duplicate records so i delete them manually.
    thanks & Regards

    You do it like this.
    SQL> select * from attendance;
       DEPT_ID ATT_DATE    ATT_KIND
           100 20-FEB-10          1
           100 20-FEB-10          1
           200 20-FEB-10          1
           200 20-FEB-10          2
    SQL> create table exceptions(row_id rowid,
      2   owner varchar2(30),
      3   table_name varchar2(30),
      4    constraint varchar2(30));
    Table created.
    SQL> alter table attendance add constraint att_pk  primary key (dept_id, att_date, att_kind) exceptions into exceptions;
    alter table attendance add constraint att_pk  primary key (dept_id, att_date, att_kind) exceptions into exceptions
    ERROR at line 1:
    ORA-02437: cannot validate (TEST.ATT_PK) - primary key violated
    SQL> select * from exceptions;
    ROW_ID             OWNER                          TABLE_NAME                     CONSTRAINT
    AAAC/yAAGAAAAAOAAB TEST                           ATTENDANCE                     ATT_PK
    AAAC/yAAGAAAAAOAAA TEST                           ATTENDANCE                     ATT_PK
    SQL> select * from attendance where rowid in (select row_id from exceptions);
       DEPT_ID ATT_DATE    ATT_KIND
           100 20-FEB-10          1
           100 20-FEB-10          1
    SQL>Asif Momen
    http://momendba.blogspot.com

  • Query to find duplicate sql executed

    What is the sql to find the duplicate sql executed and count of executions.
    I need the query ( though we can get directly the results from OEM)
    Please let me know.
    Thanks
    Naveen

    >
    What is the sql to find the duplicate sql executed and count of executions.
    I need the query ( though we can get directly the results from OEM)Get to know V$SQL, V$SQL_AREA and V$SQL_TEXT.
    Check out Christoper Lawson's Oracle performance tuning book - it's
    very good on the basics of this subject.
    HTH.
    Paul...
    Naveen--
    When asking database related questions, please give other posters
    some clues, like OS (with version), version of Oracle being used and DDL.
    Other trivia such as CPU, RAM + Disk configuration might also be useful.
    The exact text and/or number of error messages is useful (!= "it didn't work!"). Thanks.
    Furthermore, as a courtesy to those who spend time analysing and attempting to help,
    please do not top post and do try to trim your replies!

  • Query to find duplicates, update appropriately, delete one of those duplicate

    I have duplicate rows in below given table and need to cleanse it by observing another duplicate record.
    I'd like to know various ways to achieve it. (I'm confused I should use UPDATE.. (CASE WHEN.. THEN).. or MERGE or something else)
    Please find below DDL/DML.
    create table MyTable
    PKey int identity(1,1),
    CustID int,
    FirstName varchar(10),
    LastName varchar(10),
    Main varchar(10),
    Department varchar(10)
    Insert into MyTable
    select 101, 'aaa','bbb','VM','Marketing' union
    select 101, '', '','','' union
    select 102, '', 'yyy', 'Main', 'Marketing' union
    select 102, 'xxx','','','' union
    select 103, 'ppp', 'qqq', '', 'HR' union
    select 103, '', '', 'MF', '' union
    select 104, 'mmm', 'nnn', 'f', 'dept'
    select * from mytable
    --PKey CustID FirstName LastName Main Department
    --2 101 aaa bbb VM Marketing
    --3 102 xxx yyy Main Marketing
    --6 103 ppp qqq MF HR
    --7 104 mmm nnn f dept
    Cheers,
    Vaibhav Chaudhari

    Hi Vaibhav,
    Manu's has copied as a part of the below code.
    create table MyTable
    PKey int identity(1,1),
    CustID int,
    FirstName varchar(10),
    LastName varchar(10),
    Main varchar(10),
    Department varchar(10)
    Insert into MyTable--(CustID,FirstName,LastName,Main,Department)
    select 101, 'aaa','bbb','VM','Marketing' union
    select 101, '', '','','' union
    select 102, '', 'yyy', 'Main', 'Marketing' union
    select 102, 'xxx','','','' union
    select 103, 'ppp', 'qqq', '', 'HR' union
    select 103, '', '', 'MF', '' union
    select 104, 'mmm', 'nnn', 'f', 'dept'
    SELECT * FROM MyTable;
    ;WITH cte AS
    SELECT DISTINCT
    MAX(PKey) PKey,
    CustID,
    MAX(FirstName) AS FirstName,
    MAX(LastName)AS LastName,
    MAX(Main) AS Main,
    MAX(Department) AS Department
    FROM mytable
    GROUP BY CustID
    MERGE mytable AS Tar
    USING cte AS Src
    ON Tar.PKey = Src.PKey
    WHEN MATCHED THEN
    UPDATE SET Tar.CustID = Src.CustID, Tar.FirstName = Src.FirstName,Tar.LastName = Src.LastName, Tar.Main = Src.Main,Tar.Department = Src.Department
    WHEN NOT MATCHED BY SOURCE THEN
    DELETE
    SELECT * FROM MyTable
    DROP TABLE MyTable;
    If you do care about the Identity Pkey, as per the expected output, my understanding on your logic is like below.
    ;WITH cte AS
    SELECT PKey, CustID,V1,V2,V3,V4,ROW_NUMBER() OVER(PARTITION BY CustID ORDER BY v1+v2+v3+v4 DESC) AS RN
    FROM MyTable
    CROSS APPLY(SELECT CASE WHEN FirstName ='' THEN 0 ELSE 1 END AS v1) AS cat1
    CROSS APPLY(SELECT CASE WHEN LastName ='' THEN 0 ELSE 1 END AS v2) AS cat2
    CROSS APPLY(SELECT CASE WHEN Main ='' THEN 0 ELSE 1 END AS v3) AS cat3
    CROSS APPLY(SELECT CASE WHEN Department ='' THEN 0 ELSE 1 END AS v4) AS cat4
    ,cte2 AS
    SELECT DISTINCT
    CustID,
    MAX(FirstName) AS FirstName,
    MAX(LastName)AS LastName,
    MAX(Main) AS Main,
    MAX(Department) AS Department
    FROM mytable
    GROUP BY CustID
    ,cte3 AS
    SELECT c2.CustID,c2.FirstName,c2.LastName,c2.Main,c2.Department,c.PKey FROM cte2 c2 JOIN cte c ON c.CustID = c2.CustID WHERE NOT EXISTS(SELECT 1 FROM cte WHERE RN<c.RN)
    MERGE mytable AS Tar
    USING cte3 AS Src
    ON Tar.PKey = Src.PKey
    WHEN MATCHED THEN
    UPDATE SET Tar.CustID = Src.CustID, Tar.FirstName = Src.FirstName,Tar.LastName = Src.LastName, Tar.Main = Src.Main,Tar.Department = Src.Department
    WHEN NOT MATCHED BY SOURCE THEN
    DELETE
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Query to find duplicate records (Urgent!!!!)

    Hi,
    I have a to load data from a staging table to base table but I dont want to load data already present in the base table. Criteria to identify the duplicate data is thorugh a field say v_id and status_flag. If these two are the same in both staging and base table then that record must be rejected as a duplicate record.
    Kindly help me with the SQL which i need to use in a Procedure.
    Thanks

    Hello
    Another alternative would be to use MINUS if the table structures match:
    --Source rows the first 5 are in the destination table
    SQL> select * from dt_test_src;
    OBJECT_ID OBJECT_NAME
    101081 /1005bd30_LnkdConstant
    90723 /10076b23_OraCustomDatumClosur
    97393 /103a2e73_DefaultEditorKitEndP
    106075 /1048734f_DefaultFolder
    93337 /10501902_BasicFileChooserUINe
         93013 /106faabc_BasicTreeUIKeyHandle
         94929 /10744837_ObjectStreamClass2
        100681 /1079c94d_NumberConstantData
         90909 /10804ae7_Constants
        102543 /108343f6_MultiColorChooserUI
         92413 /10845320_TypeMapImpl
         89593 /10948dc3_PermissionImpl
        102545 /1095ce9b_MultiComboBoxUI
         98065 /109cbb8e_SpanShapeRendererSim
        103855 /10a45bfe_ProfilePrinterErrors
        102145 /10a793fd_LocaleElements_iw
         98955 /10b74838_SecurityManagerImpl
        103841 /10c906a0_ProfilePrinterErrors
         90259 /10dcd7b1_ProducerConsumerProd
        100671 /10e48aa3_StringExpressionCons
    20 rows selected.
    Elapsed: 00:00:00.00
    --Destination table contents
    SQL> select * from dt_test_dest
      2  /
    OBJECT_ID OBJECT_NAME
        101081 /1005bd30_LnkdConstant
         90723 /10076b23_OraCustomDatumClosur
         97393 /103a2e73_DefaultEditorKitEndP
        106075 /1048734f_DefaultFolder
         93337 /10501902_BasicFileChooserUINe
    Elapsed: 00:00:00.00
    --try inserting everything which will fail because of the duplicates
    SQL> insert into dt_test_dest select * from dt_test_src;
    insert into dt_test_dest select * from dt_test_src
    ERROR at line 1:
    ORA-00001: unique constraint (CHIPSDEVDL1.DT_TEST_PK) violated
    Elapsed: 00:00:00.00
    --now use the minus operator to "subtract" rows from the source set that are already in the destination set
    SQL> insert into dt_test_dest select * from dt_test_src MINUS select * from dt_test_dest;
    15 rows created.
    Elapsed: 00:00:00.00
    SQL> select * from dt_test_dest;
    OBJECT_ID OBJECT_NAME
        101081 /1005bd30_LnkdConstant
         90723 /10076b23_OraCustomDatumClosur
         97393 /103a2e73_DefaultEditorKitEndP
        106075 /1048734f_DefaultFolder
         93337 /10501902_BasicFileChooserUINe
         89593 /10948dc3_PermissionImpl
         90259 /10dcd7b1_ProducerConsumerProd
         90909 /10804ae7_Constants
         92413 /10845320_TypeMapImpl
         93013 /106faabc_BasicTreeUIKeyHandle
         94929 /10744837_ObjectStreamClass2
         98065 /109cbb8e_SpanShapeRendererSim
         98955 /10b74838_SecurityManagerImpl
        100671 /10e48aa3_StringExpressionCons
        100681 /1079c94d_NumberConstantData
        102145 /10a793fd_LocaleElements_iw
        102543 /108343f6_MultiColorChooserUI
        102545 /1095ce9b_MultiComboBoxUI
        103841 /10c906a0_ProfilePrinterErrors
        103855 /10a45bfe_ProfilePrinterErrors
    20 rows selected.You could use that in conjunction with the merge statement to exclude all trully duplicated rows and then update any rows that match on the id but have different statuses:
    MERGE INTO dest_table dst
    USING(     SELECT
              v_id,
              col1,
              col2 etc
         FROM
              staging_table
         MINUS
         SELECT
              v_id,
              col1,
              col2 etc
         FROM
              destination_table
         ) stg
    ON
         (dts.v_id = stg.v_id)
    WHEN MATCHED THEN....HTH

  • Query to find 2 Way Match and 3 Way Match PO numbers

    I need the details of a 2 way match and 3 way match PO Numbers. Please provide me the query to find such PO Numbers. Thanks in advance.

    Are you trying to query for 3 different PO numbers? PO1 = aaa OR PO3 = bbb?

  • Finding duplicate values in a column with different values in a different c

    I'm finding duplicate values in a column of my table:
    select ba.CLAIM_NUMBER from bsi_auto_vw ba
    group by ba.CLAIM_NUMBER
    having count(*) > 1;
    How can I modify this query to find duplicate values in that column where I DON'T have duplicate values in a different specific column in that table (the column CLMT_NO in my case can't have duplicates.)?

    Well, you can use analytics assuming you don't mind full scanning the table.....
    select
       count(owner) over (partition by object_type),    
       count(object_type) over (partition by owner)
    from all_objects;You just need to intelligently (i didn't here) find your "window" (partition clause) to sort the data over, then make use of that (the analytics would be in a nested SQL and you'd then evaluate it in outside).
    Should be applicable if i understand what you're after.
    If you post some sample data we can mock up a SQL statement for you (if what i tried to convey wasn't understandable).

  • How do I find duplicate words in a Numbers spreadsheet?

    Hello, I've created my first document on Numbers and am trying to figure out how to find duplicate words. Ideally, a list of words that repeat in the document and how many times. Is this possible? Thank you in advance for the advice

    It's easy enough to find and count duplicate entries, especially if they are all in a single column, but if you want to count individual words within multi word entries, the problem is more complicated.
    Here's an example for the 'simple' case, using a familiar 155 word passage from English literature.
    The words in the passage are separated into a single line for each word, and stripped of all punctuation. This may be done in Pages, or in Text edit, or in pretty much any word processing software or text editor. Paste the passage into a WP or text document, then use the application's Find/Replace feature to replace all of the spaces with returns. I would also do a second pass replacing all double returns with single returns, then repeat that until Find/Replace reported replacing zero occurrences.
    Punctuation was stripped using Find/Replace
    The prepared list was pasted into column A of a Numbers table.
    Formulas:
    B2: =COUNTIF($A$1:A2,A2)
    C2: =IF(AND(B>1,B=COUNTIF($A,A2)),ROW()-1,999999)
    Fill both down their respective columns to the end of the table.
    The small table is inserted as a Basic table using the Tables button. It contains a Header row, but no Header columns.
    Formula:
    A2: =IFERROR(OFFSET(Table 1 :: $A$1,SMALL(Table 1 :: $C,ROW()-1),COLUMN()-1),"")
    Fill right into B2, then fill both down to the end of the table.
    Descriptions of the functions used, along with their syntax and at least one example of their use in a table are available in the Numbers '09 User Guide, which may be downloaded via the Help menu in Numbers.
    Regards,
    Barry
    PS: Regards to the late Mr. Shakespeare, and thank you for providing the text used.

  • How to find duplicate row in sql query?

    Hi All,
    Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.

    You can use group by and having.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT   *
    10    FROM   t;
            ID
             1
             2
             3
             4
             5
             3
             4
             5
    8 rows selected.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT     id, COUNT (*)
    10      FROM   t
    11  GROUP BY   id
    12    HAVING   COUNT (*) > 1;
            ID   COUNT(*)
             3          2
             4          2
             5          2
    SQL>

  • Find Duplicate Query MySQL Syntax

    There is a "find duplicates" query in SQL that is very useful
    but I'm not sure what the syntax is for MySQL. It probably has
    something to do with select distinct, group by but I'm not used to
    to using these.
    This is one that finds all duplicates of [FULLNAME]
    SELECT CONTACTS.*
    WHERE (((CONTACTS.FULLNAME) In (SELECT [FULLNAME] FROM
    [CONTACTS] As Tmp GROUP BY [FULLNAME]
    HAVING Count(*)>1 )))
    ORDER BY CONTACTS.FULLNAME, CONTACTS.COMPANY
    Does anyone know?

    RichardODreamweaver wrote:
    > There is a "find duplicates" query in SQL that is very
    useful but I'm not sure
    > what the syntax is for MySQL.
    SELECT COUNT(*) AS repetitions, FULLNAME, COMPANY
    FROM CONTACTS
    GROUP BY FULLNAME, COMPANY
    HAVING repetitions > 1
    It's not something I have used myself, but I got it from
    MySQL Cookbook
    by Paul DuBois, published by O'Reilly. I have the first
    edition, which
    covers MySQL 4.0. I think the second edition covers MySQL
    5.0.
    If you're using MySQL on a regular basis, you or your
    employer should
    buy it immediately. It will solve most of your problems and
    repay its
    cost many times over.
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Help with Finding Duplicate records Query

    HI,
    I am trying to write a query that will find duplicate records/cases.
    This query will be used in a report.
    So, here are the requirements:
    I need to find duplicate cases/records based on the following fields:
    DOB, DOCKET, SENT_DATEI was able to do that with the following query. The query below is able to give me all duplicate records based on the Criteria above
    SELECT      DEF.BIRTH_DATE DOB,
               S.DOCKET DOCKET,
               S.SENT_VIO_DATE SENT_DATE, COUNT(*)
    FROM SENTENCES S,
                DEFENDANTS DEF
    WHERE      S.DEF_ID = DEF.DEF_ID
    AND       S.CASE_TYPE_CODE = 10
    GROUP BY  DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE
    HAVING COUNT(*) > 1;
    //I AM GOING TO CALL THIS QUERY 'X'Now, the information to be displayed on the report: defendants Name, DOB, District, Docket, Def Num, Sent Date, and PACTS Num if possible.
    The problem that I need help on is how to combine those queries together (what I mean is a sub query). the 'X' query returns multiple values. please have a look at the comments on the query below to see what I'm trying to achieve.
    here is the main query:
    SELECT      INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
    FROM      USSC_CASES.DEFENDANTS DEF,
            USSC_CASES.SENTENCES S,
            LOOKUP.DISTRICTS DIST
    WHERE      DEF.DEF_ID = S.DEF_ID
    AND      S.DIST_ID = DIST.USSC_DISTRICT_ID
    AND     S.CASE_TYPE_CODE = 10
    AND     S.USSC_ID IS NOT NULL
    AND // what i'm trying to do is: DOB, DOCKET, SENT_DATE IN ('X' QUERY), is this possible ??
    ORDER BY DEFENDANT_NAME; thanks in advance.
    I am using Oracle 11g, and sql developer.
    if my approach doesn't work, is there a better approach ?
    Edited by: Rooney on Jul 11, 2012 3:50 PM

    If I got it right, you want to join table USSC_CASES.DEFENDANTS to duplicate rows in USSC_CASES. If so:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              COUNT(*) OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE) CNT
                        FROM  USSC_CASES.SENTENCES S
               WHERE CNT > 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;If you want to exclude duplicates from the query and do not care which row out of duplicate rows to choose:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              ROW_NUMBER() OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE ORDER BY 1) RN
                        FROM  USSC_CASES.SENTENCES S
               WHERE RN = 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;SY.

  • Script to find duplicate index and how can we tell if an index is REALLY a duplicate?

    Does any one have script to find duplicate index? and how can we tell if an index is REALLY a duplicate?
    Rahul

    One more written by Itzik Ben-Gan
    The first query finds exact matches. The indexes must have 
    the same key columns in the same order, and the same included columns but in any order. 
    These indexes are sure targets for elimination. The only caution would be to check for index hints. 
    -- exact duplicates
    with indexcols as
    select object_id as id, index_id as indid, name,
    (select case keyno when 0 then NULL else colid end as [data()]
    from sys.sysindexkeys as k
    where k.id = i.object_id
    and k.indid = i.index_id
    order by keyno, colid
    for xml path('')) as cols,
    (select case keyno when 0 then colid else NULL end as [data()]
    from sys.sysindexkeys as k
    where k.id = i.object_id
    and k.indid = i.index_id
    order by colid
    for xml path('')) as inc
    from sys.indexes as i
    select
    object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
    c1.name as 'index',
    c2.name as 'exactduplicate'
    from indexcols as c1
    join indexcols as c2
    on c1.id = c2.id
    and c1.indid < c2.indid
    and c1.cols = c2.cols
    and c1.inc = c2.inc;
    The second variation of this query finds partial, or duplicate, indexes 
    that share leading key columns, e.g. Ix1(col1, col2, col3) and Ix2(col1, col2) 
    would be considered duplicate indexes. This query only examines key columns and does not consider included columns. 
    These types of indexes are probable dead indexes walking. 
    -- Overlapping indxes
    with indexcols as
    select object_id as id, index_id as indid, name,
    (select case keyno when 0 then NULL else colid end as [data()]
    from sys.sysindexkeys as k
    where k.id = i.object_id
    and k.indid = i.index_id
    order by keyno, colid
    for xml path('')) as cols
    from sys.indexes as i
    select
    object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
    c1.name as 'index',
    c2.name as 'partialduplicate'
    from indexcols as c1
    join indexcols as c2
    on c1.id = c2.id
    and c1.indid < c2.indid
    and (c1.cols like c2.cols + '%' 
    or c2.cols like c1.cols + '%') ;
    Be careful when dropping a partial duplicate index if the two indexes differ greatly in width. 
    For example, if Ix1 is a very wide index with 12 columns, and Ix2 is a narrow two-column index 
    that shares the first two columns, you may want to leave Ix2 as a faster, tighter, narrower index.
    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

  • Finding missed sequence numbers and rows from a fact table

    Finding missed sequence numbers and rows from a fact table
    Hi
    I am working on an OLAP date cube with the following schema:
    As you can see there is a fact transaction with two dimensions called cardNumber and Sequence. Card dimension contains about three million card numbers. 
    Sequence dimension contains a sequence number from 0 to 255. Fact transaction contains about 400 million transactions of those cards.
    Each transaction has a sequence number in 0 to 255 ranges. If sequence number of transactions of a card reaches to 255 the next transaction would get 0 as a sequence number.
    For example if a card has 1000 transactions then sequence numbers are as follows;
    Transaction 1 to transaction 256 with sequences from 0 to 255
    Transaction 257 to transaction 512 with sequences from 0 to 255
    Transaction 513 to transaction 768 with sequences from 0 to 255
    Transaction 769 to transaction 1000 with sequences from 0 to 231
    The problem is that:
    Sometimes there are several missed transactions. For example instead of sequence from 0 to 255, sequences are from 0 to 150 and then from 160 to 255. Here 10 transactions have been missed.
    How can I find all missed transactions of all cards with a MDX QUERY?
    I really appreciate for helps

    Thank you Liao
    I need to find missed numbers, In this scenario I want the query to tell the missed numbers are: 151,152,153,154,155,156,157,158,159
    Relative transactions are also missed, so I think it is impossible to get them by your MDX query
    Suppose this:
    date
    time
    sequence
    20140701
    23:22:00
    149
    20140701
    23:44:00
    150
    20140702
    8:30:00
    160
    20140702
    9:30:00
    161
    20140702
    11:30:00
    162
    20140702
    11:45:00
    163
    As you can see the sequence number of the last transaction at the 20140701 is 150
    We expecting that the first transaction of the next day should be 151 but it is 160. Those 10 transactions are totally missed and we just need to
    find missed sequence numbers

  • How to remove duplicate phone numbers under iMessage settings?

    I've been using iMessage for a while now and a lot of my friends have brought to my attention that every iMessage I sent showed it came from my email rather than my phone number. So I signed out of iMessage and tried logging back in using my phone number and it would not work, saying the activation did not go through. So I tried again and again throughout the day and it finally worked eventually. The problem is I get a duplicate (lots of it) of my phone numbers, I'm guessing from my countless attempts at signing in. How do I go about removing all the duplicates that are grayed out? Also why do the last three have tick marks next to them? How do I make it so that only one of them is tickmarked and delete the rest of the duplicates. I've provided screenshots below.
    Also, "waiting for activation..." has been shown under the settings for almost the whole day. How long does this take?

    I've tried signing out and back in again. It doesn't do anything. I still get the unnecesarily long list of duplicate phone numbers and have 2 or 3 of them randomly tick marked. I've tried this multiple times, it doesn't get rid of them at all. As far as I'm concerned, my friends do receive my iMessage from my number rather than my email. I just find it a nuisance to have such a long list of my phone number 25 times over. I don't think it affects anything though, but any way to get rid of them would be great.
    Also, it's been 3 days and it still says "waiting for activation" on my iMessage and Facetime settings. How long does this take? As far as I know, my friends have told me iMessaging with me is flawless but I'm confused as to why it's still trying to activate.

Maybe you are looking for

  • Why I am experiencing video freezing using FaceTime.

    Using an iMac intel OS 10.6.8 and connecting to MacBook Pro with FaceTime, I experience video freezes and broken audio. The other party (MacBook) does not seem to have the same issue leading me to believe it is something to do with the iMac. I tried

  • IDOC segment for VBKD-BSTKD_E

    Hi, I am using ORDERS04 as basic type for order creation from iDOC. For one of my requirment I need the iDOC segment for VBKD-BSTKD_E field. The field is in purchase order data at header > Ship to party view > Purchase order no. Thanks Sanjay

  • Discoverer Connections

    Hi I am in the process of doing some testing of BI Discoverer 10.1.2.0.2 as we are about to upgrade from Discoverer 9i. I am trying to create a Dynamic connection to Discoverer plus so that when a user clicks on the connection they have to enter thei

  • Type Initialization Failed

    Hello, I have an application in C# 2005, and have usede Crystal Reports 10. When I deploy this application on another machine where Visual Studio is not present, on report display it throws the following error: System.TypeInitializationException: The

  • Tourbles with HP Officejet 7500 E910

    I have my HP Officejet 7500 E910 network, now i can not connect to my network switch, nor by wireless. Also i can not move into the printer software from its small monitor, the bottoms on the sides of the monitor are not working, Any help how to retr