Having a backup plan always is always better

Today we got a client ask us to upload data from excel sheet into sql server, update data to the sql server database.

Well, my collegues usings a simple script that copy the values from the excel file. If there are 1,000 records, there will be 1,000 rows of sql update statements.

I decided to do it using another method and a good friend of our - DTS.

Actually, I got another method which uses openrowset which also works but the database server doesn't allow MSDTC to start so bo bian. The DBA scared to corrupt the production db server simply by starting the MSDTC service on the server, which I suspected was installed incorrectly, thats why it refuse to restart. Anyway, i think its ridiculous that a simple MSDTC service can corrupt a database server. 

So, early in the morning i use DTS to upload to a temp table and I wrote a simple sql script to update the required table using the same Primary key on both tables as a join. Following that, the client call again, and she said the excel data is wrong, had to resend and ask us to re-upload again.

Thinking back, although writing 1,000 lines of sql script is simple but due to unforeseen cirumstances using DTS and a simple update statement can save the day and increase productivity and reduce the amount of effort wasted.

 

 

 

 

Published Wednesday, September 26, 2007 3:13 PM by darenhan

Comments

# re: Having a backup plan always is always better

Friday, September 28, 2007 3:24 PM by hannes

DTS has its problems though... I'm not a big fan.

Generating the sql in excel is simple though.. its a 5 min job. Just insert parts of the sql statements into columns inbetween the values, and finally have a column with =CONCATENATE(A1,B1...) to give you your final update statement, then copy + paste the script all at once.

If it is a common task though, I prefer to write a small windows application which uses OLEDB to read from Excel and goes through the usual data access layer to update data. This way it can have some intelligence and do inserts/updates and check for invalid data.

# re: Having a backup plan always is always better

Saturday, September 29, 2007 4:15 PM by darenhan

yes but not when the customer changes data very frequently in the excel file. If there are 10,000 rows of data in the excel file, you got to insert your sql in excel 10,000 times. very tedious and not suitable when the customer says he wants it done straightaway.

Powered by Community Server (Commercial Edition), by Telligent Systems