Checking for duplicate data

Hi guys,
I currently have a column in one of my database tables which is an id, the begining of the ID either starts with ab, ac, or ad followed by a few numbers (the amount of numbers varies from 6-8) What I want to be able to do is to check if there are multiple record of the same ID disregarding the front 2 letters and list the duplicates, ie I want to be able to run a select statement which will display the following id as being duplicates:
ab12345
ac12345
ad12345
The above 3 ids would flag up as duplicates. Would this be possible?
Any help on this matter would be greatly appreciated.
Thank you.

Maybe (seems you want rows flagged)
with
data(some_id) as
(select 'ab12345' from dual union all
select 'ac12345' from dual union all
select 'ad12345' from dual union all
select 'ad123456' from dual union all
select 'ad654321' from dual union all
select 'ab123456' from dual union all
select 'ac1234567' from dual union all
select 'ad1234567' from dual union all
select 'ab12345678' from dual
select some_id,
       case when count(*) over (partition by substr(some_id,3)
                                    order by null rows between unbounded preceding
                                                           and unbounded following
                               ) > 1
            then 'DUP'
       end duplicate_flag
  from dataRegards
Etbin

Similar Messages

  • Check for duplicate record in SQL database before doing INSERT

    Hey guys,
           This is part powershell app doing a SQL insert. BUt my question really relates to the SQL insert. I need to do a check of the database PRIOR to doing the insert to check for duplicate records and if it exists then that record needs
    to be overwritten. I'm not sure how to accomplish this task. My back end is a SQL 2000 Server. I'm piping the data into my insert statement from a powershell FileSystemWatcher app. In my scenario here if the file dumped into a directory starts with I it gets
    written to a SQL database otherwise it gets written to an Access Table. I know silly, but thats the environment im in. haha.
    Any help is appreciated.
    Thanks in Advance
    Rich T.
    #### DEFINE WATCH FOLDERS AND DEFAULT FILE EXTENSION TO WATCH FOR ####
                $cofa_folder = '\\cpsfs001\Data_pvs\TestCofA'
                $bulk_folder = '\\cpsfs001\PVS\Subsidiary\Nolwood\McWood\POD'
                $filter = '*.tif'
                $cofa = New-Object IO.FileSystemWatcher $cofa_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
                $bulk = New-Object IO.FileSystemWatcher $bulk_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
    #### CERTIFICATE OF ANALYSIS AND PACKAGE SHIPPER PROCESSING ####
                Register-ObjectEvent $cofa Created -SourceIdentifier COFA/PACKAGE -Action {
           $name = $Event.SourceEventArgs.Name
           $changeType = $Event.SourceEventArgs.ChangeType
           $timeStamp = $Event.TimeGenerated
    #### CERTIFICATE OF ANALYSIS PROCESS BEGINS ####
                $test=$name.StartsWith("I")
         if ($test -eq $true) {
                $pos = $name.IndexOf(".")
           $left=$name.substring(0,$pos)
           $pos = $left.IndexOf("L")
           $tempItem=$left.substring(0,$pos)
           $lot = $left.Substring($pos + 1)
           $item=$tempItem.Substring(1)
                Write-Host "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp"  -fore green
                Out-File -FilePath c:\OutputLogs\CofA.csv -Append -InputObject "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp"
                start-sleep -s 5
                $conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=PVSNTDB33; Initial Catalog=adagecopy_daily; Integrated Security=TRUE")
                $conn.Open()
                $insert_stmt = "INSERT INTO in_cofa_pvs (in_item_key, in_lot_key, imgfileName, in_cofa_crtdt) VALUES ('$item','$lot','$name','$timestamp')"
                $cmd = $conn.CreateCommand()
                $cmd.CommandText = $insert_stmt
                $cmd.ExecuteNonQuery()
                $conn.Close()
    #### PACKAGE SHIPPER PROCESS BEGINS ####
              elseif ($test -eq $false) {
                $pos = $name.IndexOf(".")
           $left=$name.substring(0,$pos)
           $pos = $left.IndexOf("O")
           $tempItem=$left.substring(0,$pos)
           $order = $left.Substring($pos + 1)
           $shipid=$tempItem.Substring(1)
                Write-Host "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp"  -fore green
                Out-File -FilePath c:\OutputLogs\PackageShipper.csv -Append -InputObject "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp"
    Rich Thompson

    Hi
    Since SQL Server 2000 has been out of support, I recommend you to upgrade the SQL Server 2000 to a higher version, such as SQL Server 2005 or SQL Server 2008.
    According to your description, you can try the following methods to check duplicate record in SQL Server.
    1. You can use
    RAISERROR to check the duplicate record, if exists then RAISERROR unless insert accordingly, code block is given below:
    IF EXISTS (SELECT 1 FROM TableName AS t
    WHERE t.Column1 = @ Column1
    AND t.Column2 = @ Column2)
    BEGIN
    RAISERROR(‘Duplicate records’,18,1)
    END
    ELSE
    BEGIN
    INSERT INTO TableName (Column1, Column2, Column3)
    SELECT @ Column1, @ Column2, @ Column3
    END
    2. Also you can create UNIQUE INDEX or UNIQUE CONSTRAINT on the column of a table, when you try to INSERT a value that conflicts with the INDEX/CONSTRAINT, an exception will be thrown. 
    Add the unique index:
    CREATE UNIQUE INDEX Unique_Index_name ON TableName(ColumnName)
    Add the unique constraint:
    ALTER TABLE TableName
    ADD CONSTRAINT Unique_Contraint_Name
    UNIQUE (ColumnName)
    Thanks
    Lydia Zhang

  • Set Check for Duplicate Invoices.

    Hi,
    what is the difference if is set "<b>Set Check for Duplicate Invoices</b>"
    in MIRO?
    Best regards

    HI,
    This check will prevent incoming invoices being accidentally entered and paid more than once.
    You can choose whether to activate or deactivate the check criteria of company code, reference document number and invoice date for each company code. The more criteria that you activate, the lower the probability of the system finding a duplicate invoice.
    The company code check makes sense if you work with more than one company code.
    Depending on the reference document number entry, the system checks as follows:
    1. If you have entered a reference document number, the system checks whether the invoice matches in the following attributes:
    Company code
    Vendor
    Currency
    Invoice date
    Reference document number
    2. If you have not entered a reference document number, the system
    3. checks whether the invoice matches in the following attributes:
    Company code
    Vendor
    Currency
    Invoice date
    Amount in
    document currency
    Depending on the system settings, a warning message or an error message appears if the system finds an invoice that matches all attributes.
    Requirements
    The field Chk double inv. (Check for duplicate invoice) must be flagged on the Accounting view in the vendor master record.
    Regards
    Aasif

  • Checking for duplicate primary keys on row inserts

    Checking for duplicate primary keys on row inserts
    I have a situation where I will be making bulk table inserts knowing that the primary key value will in some cases already exist. In this is the case I simply want to ignore the duplicate inserts.
    Should I be performing a sub-query on the table and using a statement like:
    where not exist in
    Or is there a cleaner way of discarding or checking for duplicates on insert.
    My concerns were mainly one of performance, as my routine will be inserting a few thousand rows in its operation.

    The MERGE commnad is a good option when a large percentage of the data will exist in the target because it is much more efficient to attempt to update then insert when the update affects zero rows than capture an error and convert it to an update.
    However, since in this case it would appear that only a few rows will alreadys exist and we want to ignore the duplicates when they exist then
    begin
    insert
    exception
    when dup_value_in_index then null;
    end
    would be the way to code this one. The bulk insert version has in 9.2 the ability to store the errors so that they can all be handled at once which means the rest of the array insert can work.
    HTH -- Mark D Powell --

  • Can I exit from paintComponent?  ...or... how can I check for invalid data?

    I'm writing a calendar applet for a programming class and I've nearly completed it but I'm stuck at checking for valid data.
    What seems to be happening is that paintComponent() is being called before actionPerformed.
    In actionPerformed (when they click the button), it checks to make sure they entered a valid month (1 to 12). If the didn't it dispalys a message, but if they did it calls repaint().
    But even if repaint() isn't called, Java still seems to call it before actionPerformed and I get exceptions.
    So I tried checking inside of paintComponent() by using a simple if(...) return; but that doesn't seem to do anything... it just keeps going through with the method.
    So -- Once the user presses my button I want to make sure the data is valid before repainting the screen. How can I do this?

    I validate it in actionPerformed which is called by
    the action listener... that is what you meant right?
    The problem is that it seems paintComponent() is being
    called before I can validate the data with
    actionPerformed(). I need to stop paintComponent()
    from always being calledMVC. (Model, View, Controller)
    Initially the internal value of the data (the model) should be valid (or null with a check in the paintComponent method)
    paintComponent (the view part) shows the state of the valid data.
    You press the button.
    actionPerformed is called (the controller).
    It checks the value and, if valid, writes it to the data (model), then updates the view.
    At no point will the view have to render invalid data, because the model is only updated after actionPerformed checks the value.
    The pattern may be applied with different classes performing the three roles, or different methods in the same class (sometimes it's easier that way for simple cases).
    Pete

  • How do i check ensure that SAP checks for duplicate vendor invoice numbers?

    Hi Experts -
    How do I verify that SAP checks for duplicate vendor invoice numbers and blocks duplicate invoices from being paid?
    Thanks!

    Hi
    Pls chek the settigs by following the path
    IMG>Materials Management>Logistics Invoice Verification>Incoming Invoice>Set Check for Duplicate Invoice.
    Here you make the settings for creating a duplicate invoice check.
    Moreever, in the vendor master, you need to tick the check box for duplicate invoice check.
    I suggest you search the Forums before posting a query. There are lots of postings on this issue.
    Thanks & regards
    Sanil K Bhandari

  • Problem in Set Check for Duplicate Invoices

    Hi,
    I have did all the required setting s for check duplicate invoice , but when i do miro , its not giving any error or warning msge.. i did all the config  as per blw link..
    FYI-  in migo, i have entered the 3434 as a invoice ref # in delveriy note column and while doing miro , i have entered 3434 in ref column and give the 3434 as a dlvery note # in item tab .. but its not giving any error?
    Pls guide, where the mistake has gone wrongly??
    Problem in Set Check for Duplicate Invoices
    Edited by: UJ on May 15, 2009 1:45 PM

    Hello,
    Hope you have done all the required configurations for the checking of double invoice and ticked the vendor for the double invoice checking in vendor master record.
    You have to understand the way the system does the double invoice check.
    As per the configuration, if the system identifies an invoice for a vendor whose double invoice check is activated, at the time of MIRO, system will update a separate table.
    So system will check for the double invoice entry among the invoices entered after making the tick in the vendor master.
    i meant to say that, if you are introducing this double invoice check in between the transactions, the check will be valid only for the invoices entered after the activation of double invoice check.
    Regards

  • Check for duplicate invoices and trigger a workflow

    Hello All,
        I have a requirement to check for duplicate invoices in AP(Accounts payable) and trigger a workflow when duplicate invoices are found. I a not sure how to do any of the above. Please  let me know if you have any information on:
    1) Checking for duplicate invoices in AP
    2) Trigger a workflow
    Are there any standard workflows that checks duplicate invoices?
    Thanks.
    --Mithun

    Hi MD,
    I doubt if system gives an error on FI side when a duplicate invoice is posted.
    I feel you would require a BAdi for it, where you can call your WF using FM SAP_WAPI_START_WORKFLOW.
    Hope it helps.
    Aditya
    P.S also ask your Func Consultants, if there are any settings in the Customization, where you could capture Inv Dt, Inv Amt, Vendor, Company code.
    Edited by: Aditya Varrier on Oct 15, 2008 9:38 AM

  • How can I check for duplicates in Apple Photos?

    Can't use my existing apps to check for duplicates in Apple Photos as they only work with iPhoto folders. Any ideas how I can get around this gap?
    OS X 10.10.3

    Duplicate Annihilator for Photos:  http://brattoo.com/propaganda/#photos
    PowerPhotos: http://www.fatcatsoftware.com/powerphotos/

  • Does itunes check for duplicate purchases?

    I got a new version of itunes and I cannot have my purchased next to my new purchases.  Does itunes check for duplicates? Or are they happy to take your money?

    Maybe they will in a future update. Im not sure but I think they use to do this. IF they did Id say they stopped to make the record companys happy (And alittle richer)

  • GOS - check for duplicate Attachments

    Hi guys!
    Fianlly i managed it to add a URL to GOS in my abap program
    i used the following FMs
    CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
    CALL FUNCTION 'SO_OBJECT_INSERT'
    CALL FUNCTION 'BINARY_RELATION_CREATE'
    So what i do is running an abap report in a batch job which adds me the necessary urls.
    Now i need to now how i can check for duplicates in the gos. In particular check if this link is already there or not?
    who knows?
    thanks!!

    thank you, that helps me alot.
    Just one last thing,
    How can i find the URL value (the link actually) now?
    thanks!

  • How to check for duplicates - with a twist?

    As I'm importing music from my CD collection, is there a way to automatically check for duplicates - with an unusual twist?
    I already imported about 70 CDs using AAC format.
    I just bought a huge external drive specifically for storing my entire collection of CDs and LPs. Now that I have lots of space, I want to import everything in Apple Lossless format.
    Is there an automatic (or at least painless) way to check for duplicates as I'm importing CDs, and to have the old AAC music files over written by the new Apple Lossless files?

    Hi Clinto,
    Do you see the column headers above in itunes? They say Title, Album, Artist, etc. I don't know if it's the same for MAC but in Windows, Right Click on the column headers and click "Kind". This will display the format each song is in. If your column headers already take up all of your screen, you're gonna have to uncheck one to make room for "kind".
    Oh! and to overwrite existing files, make sure the ID3 tags are filled exactly to the old ones prior to ripping, though you don't need to fill all of them. I think you just fill the Artist, Album Artist, Album, and Title. A window will appear as you start to rip. It will ask if you want to overwrite the existing files, click "Yes". Again, don't know about Mac but it works this way in Windows.
    Message was edited by: fullcream

  • How can I sync my contacts from the iPhone to google contacts while checking for duplicates?

    I have been using Outlook to sync contacts and it works well.  Now I would like to get rid of Outlook and put the contacts that I have into my gmail and Yahoo contact accounts and keep all 3 in sync.  When I do it the first time, I'd like to be able to check for duplicates.  Is there a way to do this?

    If you want your contacts to remain in sync across iOS devices, then you can use any Exchange-type of account.  For example, once you have a "clean" set of contacts with no duplicates, you could upload that into iCloud so that any change you make from your iPad would be reflected on your iPhone.  You don't have to use iCloud for e-mail since your devices can pull a contact from iCloud for use with GMail or Yahoo.
    But you can also set GMail up as an Exchange account if you don't want to use iCloud.  The GMail account type in iOS is not Exchange, but you can set it up that way:
    http://support.google.com/mobile/bin/answer.py?l=en&topic=14252&answer=138740
    The benefit of doing this is (a) your Google contacts remain in sync across all your devices, and (b) your GMail will then support Push notification.  Just one caveat, when you do this then the default behavior when you delete an e-mail is such that it is archived to your "All Mail" folder in GMail.  The only way to change this behavior is to use your device's Safari to navigate to m.google.com/sync and change the setting on Google's server for each of your devices.  This is a one-time thing, but important if you want trashed e-mails to really go to Trash.
    As far as Contact Management Software options to clean things up, Google search is the only recommendation I have

  • Check for Duplicate Credie Memos

    Hi ,
    We have set up the Duplicate invoice check for our company code.
    Also, in the vendor master we have the " Chk. duplicate invoice " activated. This should check both the invoices and credit memos for duplicate entries.
    However, the same is not working in the case of credit memos and all the parameters such as company code , reference and the invoice date are same for both the credit memos ( even the amount and other parameters ). In the documentation, it is mentioned that this would work for both the invoices and credit memos.
    Still the system does not issue a warning message for the same.
    Can anyone suggest .
    Thanks,
    Srikanth.

    Hi,
    lease check the below OSS note:-
    [https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=31771]
    [http://help.sap.com/saphelp_afs30b/helpdata/en/ce/4f3e39ea3aee02e10000000a114084/content.htm]
    Regards,
    Gaurav

  • Check for duplicate Credit Note

    Hi All,
    Is there any way to block duplicate Credit note (Debit note) for Vendor just like we can block invoice by placing check on 1. Co. Code, 2. Invoice Date and 3. Reference check. 
    For my client, many times a credit note is getting processed twice or more. Is there any way we can block them by using say Credit note no. for example.
    Rg
    VK

    Hi Vijay,
    Credit Note dublicate check works in similar fashion as Invoice. You just needs to activate duplicate invoice check in Vendor Master data.
    An entry is created in table BSIP based on which this dublicate check is performed. In case Vendor Master Data is not updated then this table is not updted and checked for duplicacy.
    I hope it helps. Do revert back if there are still issues.
    Regards,
    Binay Agarwal

Maybe you are looking for

  • Need help with FFT for Vibration Analysis

    Hello all, I am acquiring data into LabVIEW from an accelerometer. The acceleration (in g's as determined within MAX) time domain graph works fine. However, I wish to do analysis using an FFT spectrum. All my attemps at wiring my time domain accelera

  • Using a timer as a score system

    Hey Actionscripters, I've recently started using Flash (Action Script 2.0). For one of the projects at school they are getting us to essentially make our own puzzle games from scratch. On the frame at which the puzzle sits I have a big button that sa

  • Using shapes for the background?!

    Hello everyone! This is my first website with muse. I do love this program just ran into a few issue, first problem is im using a white shape to put my content on and while this works it now has allowed you to scroll right to see the whole shape. The

  • Faulting module name: Flash10e.ocx, version: 10.0.45.2

    Getting these flash errors periodically in my application event log. Log Name:      Application Source:        Application Error Date:          6/7/2010 10:12:29 AM Event ID:      1000 Task Category: (100) Level:         Error Keywords:      Classic

  • Problem in sending arguments in rmi

    hi, i defined a class and sent the object of this class from the rmi client to the server as an argument. the class name is myclass. i have the myclass.class file on the server. then the error info is java.rmi.MarshalException: error marshalling argu