April 23, 2009 at 11:16 am
Ihave 5 csv files that I need to insert to the table. They contain 375000 records in total. Is there solution if one of the records are bad put it in seperate table(Errors) and continue putting good records to the table.
Bad record would be if this record already exists and I have primary key set for this wan't get duplicate records Thank you
April 23, 2009 at 11:24 am
if exists (select 1 from DestinationTable where PKField(s) = value(s) from CSV)
insert into ErrorTable
else
insert into DestinationTable
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 24, 2009 at 9:40 am
Is there something from SQL Server I can select to get data from csv and put it to the table. I hace 5 csv files
April 24, 2009 at 10:20 am
Use SSIS to put these Five files into a staging table, and then use the code that WayneS has provided to copy the new data from the staging table into the destination table.
If you are using SSIS you can use the execute sql task to run the code
April 24, 2009 at 11:31 am
yulichka (4/24/2009)
Is there something from SQL Server I can select to get data from csv and put it to the table. I hace 5 csv files
You can use the OpenRowset function. Search on google for how to set it up for csv files.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply