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.
Author |
Topic |
preetpalkapoor
Starting Member
6 Posts |
Posted - 2013-03-28 : 03:53:52
|
Hi , I have been given an task to load a text file to a database which is simple but the file may contain the duplicate records which are already present in the DB table. So i want to load the correct records and keep other records which are not loaded to table in another text file.Example:text file with source data:ID,Name1,john2,maya3,amir4,nehaDatabase table:ID(primary key),name(varchar(50))101,sneha102,michael1,john4,nehaNow i want the rows in text file with ID=2,3 get loaded to database table and new text file is created with data 1,john and 4,neha...Can you please help me in this .Preetpal kapoor |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-28 : 05:20:15
|
you can use several methodsone method is to use ssis and then use a lookup task to lookup records against table based on ID,name fields. Then attach nomatch output to your destination table.ANother method is to use OPENROWSET and use query likeSELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=<path here>;', 'SELECT * FROM [filename.txt];' ) tWHERE NOT EXISTS (SELECT 1 FROM Table WHERE ID = t.ID AND name = t.name) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|