Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Duplicate Records on the Table

Author  Topic 

rafael.javellana
Starting Member

10 Posts

Posted - 2011-06-01 : 18:27:02

Good Day guys,

I need help, I have a table "List" that everyday I import records on it, the key field is "Phone". The problem is everyday the records I imported has a duplicates that exist on the previous batch of list/records. My questions is how can I update the new records if it is already existing on the previous batch of records and it is also on the new batch that I have to import. Actually I import data on the table "List" without checking duplicates since it is requested by the client.

Here's the logic:

1. Import "ListNEW" to "ListOLD"
2. Check if field "Phone" from "ListNEW" exist on the "Phone" on "ListOLD"
3. If #2 is TRUE, then update the "Lock" field of "ListNEW" based on "Phone" field from "ListOLD".

Thanks.


rfjavellana

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-01 : 18:45:30
Could you show us a quick data example to make this more clear? Show both a duplicate and a unique for ListNEW and then show us what ListOLD will look like after we are done.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rafael.javellana
Starting Member

10 Posts

Posted - 2011-06-02 : 17:20:15
Hi Tara first of all thank you.

Here is the table sample:

ListOLD

Name Phone Lock
Larry 1234567890

ListNEW

Name Phone
Larry 1234567890

If after importing, the record on ListNEW exist based on field "Phone" on the ListOLD table, the field "Lock" on ListOLD table will be updated for the record just imported from ListNEW, so this will be the data on the table ListOLD after the process:

ListOLD

Name Phone Lock
Larry 1234567890 1
Larry 1234667890 2

Thanks.

rfjavellana
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-03 : 12:02:31
how did it end up having two records after update? i think what you want is insert

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rafael.javellana
Starting Member

10 Posts

Posted - 2011-06-03 : 14:55:39

the record is from ListNEW, I will IMPORT it to ListOLD then there will be two same record, my question is after the import, how can I check if the record from ListNEW already exist on the ListOLD, if it exist, the query will update the lock field for the duplicate records.

Thanks.

rfjavellana
Go to Top of Page

rafael.javellana
Starting Member

10 Posts

Posted - 2011-06-03 : 18:13:36
by the way, shall I say ListOLD will be replace by TableOld and ListNEW will be replace by FileA, just to make my questions more clearer.

Thanks.

rfjavellana
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-05 : 03:39:47
you can use ROW_NUMBER() for that. see below

http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

for getting records from file use OPENROWSET or OPENQUERY

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -