Home » excel » Update SQL Server (2014) table from an Excel email attachment

Update SQL Server (2014) table from an Excel email attachment

Posted by: admin April 23, 2020 Leave a comment

Questions:

We track IPs that attack our site. First attack, we temp block them. Tf they ever attack again then we permanently blacklist them. Information for each attack by each IP is stored in perpetuum. Twice daily, reports with an Excel spreadsheet with all pertinent information is emailed to various people, and then the information is manually added to a massive spreadsheet. We’ve recently spun up a new box with SQL server and I’ve added all of the existing information to a table in the new database.

As I’m new to this, I would like to know if there is a way to send the daily spreadsheets to this new sql server and have it parse out the excel attachment and update our master tracking table. The spreadsheet will always have the same structure (15 columns and header and footer rows) with varying row quantities, and of course it matches the existing table structure.

I’ve been googling it and am only able to find queries (ba dum tish) on how to make SQL export to excel and send an email with Database Mail. Can’t find anything on sending en email TO sql server and having it process an attachment.

How to&Answers:

You can make use of the SQL Server Integration Services(SSIS). You can write an SSIS package that import the data from the given Excel spreadsheet to a table and
then from that table you can write insert or update statements to your production table. You can use “Data Flow task” to Import the Data from the excel file and then write an ” Execute SQL Task” which will update the values to Production table. Remember that you will have to keep the Excel file in the same folder all time (or else you can use dynamic statements to get the file name dynamically using Variables). Once you have completed the package you can schedule the package as an SQL Server Job which will run periodically and hence the data will be automatically updated.

Please refer this video for a basic idea about SSIS :
Import Data From Excel to SQL Server Using SSIS

Answer:

Twice daily, reports with an Excel spreadsheet with all pertinent information is emailed to various people,

Try saving the File to a location and then use SSMS Export,Import Wizard ..This package can be saved and set to Run Daily

Here is a step by step tutorial covering the same..

https://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

<a href="https://exceptionshub.com/category/sql-server”>More Answers>