question

bhanupratapsngh9 avatar image
bhanupratapsngh9 asked

Insert only new data from excel to sql 2008 r2 bulk data

Respected Geeks !! Good day to you and thanks in advance its so urgent i need it as i am new to my company so please help me to complete my task i have an excel file which has crores data and i have same copy of a table which will contain data of that excel file and i will insert new records daily from excel to that table but if some records matched i will update that if not matched i will have to insert in that table. what will be best practice to perform it waiting for your valuable advise thanx a ton...
insertbulk-insert
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Dave_Green avatar image
Dave_Green answered
There are a variety of methods to get data from Excel into SQL Server, and without knowing more details I'd suggest you look at SSIS in the first instance - [see this walkthrough][1]. I also suggest that once your data is in SQL Server (you could, for example, use a staging table to hold the data to be updated) you look at using the [MERGE statement][2] to update or insert the records as your criteria dictate. [1]: https://www.simple-talk.com/sql/ssis/moving-data-from-excel-to-sql-server---10-steps-to-follow/ [2]: http://msdn.microsoft.com/en-us/library/bb510625.aspx
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bhanupratapsngh9 avatar image bhanupratapsngh9 commented ·
dear Dave thank you very much for quick response My dear i will use merge method i will need to make 2 same tables 1st one to hold same values from excel and second one to store data after merge like table A and B A will hold all data uploaded by excel daily basis - Source table for merge B will hold all unique data new and old (updated and inserted )- target table for merge am i understanding right?
0 Likes 0 ·
Dave_Green avatar image Dave_Green ♦ commented ·
That sounds about right - import the data as is, then use MERGE to update the existing or insert the new records.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.