Update database with excel

There are many ways to do this. I’d recommend something like this, to push data from Excel to SQL Server.

Sub ButtonClick()
'TRUSTED CONNECTION
    On Error GoTo errH
   
    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strPath As String
    Dim intImportRow As Integer
    Dim strFirstName, strLastName As String
   
    Dim server, username, password, table, database As String
   
   
    With Sheets("Sheet1")
           
            server = .TextBox1.Text
            table = .TextBox4.Text
            database = .TextBox5.Text
           
           
            If con.State <> 1 Then
       
                con.Open "Provider=SQLOLEDB;Data Source=" & server & ";Initial Catalog=" & database & ";Integrated Security=SSPI;"
                'con.Open
       
            End If
            'this is the TRUSTED connection string
           
            Set rs.ActiveConnection = con
           
            'delete all records first if checkbox checked
            If .CheckBox1 Then
                con.Execute "delete from tbl_demo"
            End If
       
            'set first row with records to import
            'you could also just loop thru a range if you want.
            intImportRow = 10
           
            Do Until .Cells(intImportRow, 1) = ""
                strFirstName = .Cells(intImportRow, 1)
                strLastName = .Cells(intImportRow, 2)
               
                'insert row into database
                con.Execute "insert into tbl_demo (firstname, lastname) values ('" & strFirstName & "', '" & strLastName & "')"
               
                intImportRow = intImportRow + 1
            Loop
           
            MsgBox "Done importing", vbInformation
           
            con.Close
            Set con = Nothing
   
    End With
   
Exit Sub

errH:
    MsgBox Err.Description
End Sub

You can also try this, which uses a Where Clause.

Sub InsertInto()

'Declare some variables
Dim cnn As adodb.Connection
Dim cmd As adodb.Command
Dim strSQL As String

'Create a new Connection object
Set cnn = New adodb.Connection

'Set the connection string
cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Northwind;Data Source=Excel-PCSQLEXPRESS"
'cnn.ConnectionString = "DRIVER=SQL Server;SERVER=Excel-PCSQLEXPRESS;DATABASE=Northwind;Trusted_Connection=Yes"


'Create a new Command object
Set cmd = New adodb.Command

'Open the Connection to the database
cnn.Open

'Associate the command with the connection
cmd.ActiveConnection = cnn

'Tell the Command we are giving it a bit of SQL to run, not a stored procedure
cmd.CommandType = adCmdText

'Create the SQL
strSQL = "UPDATE TBL SET JOIN_DT = '2013-01-22' WHERE EMPID = 2"

'Pass the SQL to the Command object
cmd.CommandText = strSQL


'Execute the bit of SQL to update the database
cmd.Execute

'Close the connection again
cnn.Close

'Remove the objects
Set cmd = Nothing
Set cnn = Nothing

End Sub

SQL Spreads solves some common data management problems for Microsoft SQL Server. It makes it fast and simple to update an SQL table from an Excel spreadsheet. And it gives you the control you need to manage data entered by various users on a collaborative team.
a demo of how to update an SQL table from Excel with SQL Spreads

End users love working in Excel

End users love working in Excel. They know the tool, and they are free to do what they want. That’s the heart of the much-loved Excel application, but also the start of problems for the people taking care of the data. The freedom to add cells and enter “whatever-you-like” values causes huge problems when trying to store and summarize the data in a structured way.

Updating or collecting some “not-available-in-our-systems” data from colleagues is often done by mailing out some Excel file or putting a spreadsheet on a file share.

When users update data in an Excel spreadsheet that should be saved or update in an SQL table, problems like these usually occur:

  • Cells in the spreadsheet can contain invalid data types.
  • There will be problems when users change the layout of the sheet.
  • Difficulties to keep track of previous versions of the Excel spreadsheet.
  • Hard to track who has changed a specific value in a sheet.
  • Troublesome to extract Excel data (with a tool such as SSIS).
  • There can be a delay of several hours between when a user enters the figures and when they appear in the database.

In finance, IT and other fields, structured data is a vital part of the operations. In those fields, you can — literally in minutes — let your end-users update data in structured SQL tables themselves – using Excel. No coding experience or extensive training is necessary.

Here’s information on how you can use SQL Spreads, an Microsoft Excel Add-In, to efficiently and accurately update an SQL Server database from Excel. I will show how to easily bring in your SQL Server tables into Excel for easy updating/management. Then show you how to share the document with your end users and how to keep track of data quality.

How to Update an SQL Table from Excel

To set up an Excel document to work with the data in an SQL Server table, follow these few simple steps:

  1. Download and install the SQL Spreads Excel Add-In.
  2. Go to the SQL Spreads tab in Excel and select Design mode.
  3. A list of databases will appear on the right. Chose the database you are using and select an SQL table to update from Excel.
  4. From the Columns tab you can fine-tune how your table is presented in Excel. You can select the columns you want to update, rearrange them into the order you prefer, and change their names if desired.
  5. When you finished fine-tuning your table, go to the spreadsheet and start updating the data from SQL Server. When you press the Save button the changes will be saved back to your SQL Server table.

There are also several other great benefits of the Designer to easily connect an Excel spreadsheet to a table in SQL Server. For example:

  • Set which columns are editable and which are “read-only”
  • Select which rows in the database are loaded into the Excel spreadsheet
  • Enable Change Tracking and the application will then insert the date and time when a row is changed, as well as the user making the change.
  • Show drop-down lists where the user can select a readable text instead of a key value for columns relating to other tables.

Let your non-technical users update and manage the SQL Server data

After you exit the Design mode you can share your Excel document like any other Excel file. All the settings will follow the document and other users can use your Excel file to update the SQL tables from Excel.

But maybe one of the biggest benefits of SQL Spreads is its ease of use. And the benefits are not only for administrators but also for authorized users throughout your business or enterprise. Non-technical users can use SQL Server-connected Excel documents that you create and share with them. The result will be an accurate and effective collaboration with safeguards including built-in conflict detection.

Assured Data Quality

To get the highest possible quality of data, SQL Spreads uses several methods to guarantee the validity of the entered data:

  • When figures are entered, they are validated against the types of the database columns, and the user receives immediate feedback.
  • Each changed row is tracked in the database to see when a row was changed and by who.
  • A built-in conflict detection system enables safe and easy collaboration.
  • When sharing the document with others, they can be given an Editor role to disable the Design mode to protect the Excel sheet set up that you’ve created.

Automatic Lookup of key values from other tables

Databases contains relations, and a table with keys relating to other tables can be hard to update manually.

When updating a SQL Server table from within Excel, SQL Spreads can lookup those key values in other tables and show drop-down lists where the user can select a readable text instead of a keys value. When the changes are saved to the database, the looked up key will be saved to the database.

Familiar and User-friendly Excel Interface

The data in SQL Server tables can be directly updated from Excel. Users are authenticated using their Windows Login and can only work with the Excel documents for which they are authorized.

Data is automatically validated when users enter their figures through SQL Spreads. And data from other Microsoft Excel documents can be pasted directly into the SQL Server connected documents.

A Low-Stress Solution with High Value to Your Organization

With SQL Spreads, you can:

  • Use Excel to work with data in SQL Server tables.
  • Let non-technical users work with the SQL Server data.
  • Ensure that the entered data is valid.

But more far-reaching benefits can be offered to your business or enterprise by using SQL Spreads. You will immediately see time savings across the board.

  • First, the setup is really fast and simple.
  • Second, when end-users enter data, SQL Spreads will guide them through the right way to enter the data.
  • Third, data owners will have the advantage of being able to easily access centralized data through Excel.
  • Fourth, you can put an end to struggling with importing Excel data using SSIS or maintaining VBA scripts.
  • Lastly, no more troubleshooting and correcting problems created by users altering the spreadsheet.

Those time-consuming processes and frustrations are replaced by SQL Spreads with fast, reliable data management.

Try SQL Spreads First-Hand to Take Control of your SQL Server Data Management

Try SQL Spreads by downloading the new SQL Spreads trial from this page.

There is also a demo video available showing how you can use SQL Spreads to create an Excel document to update the SQL table from Excel.

Editors note: This blog post was originally published for a previous version of SQL Spreads and has been completely revamped and updated for accuracy and comprehensiveness.

Johannes

Johannes Åkesson

Worked in the Business Intelligence industry for the last 15+ years.

Founder of SQL Spreads – the data management
solution to import, update and manage
SQL Server data from within Excel.

How to Update Access Database from Ms Excel

In this tutorial, we discuss about how to update Access Database from Excel. As we know, we can import or export data between Ms Access and Ms Excel.

Link Ms Excel with Access Database

First thing to do is to link the spreadsheet in Ms Excel with the database in the Ms Access. To do this, follow the steps:

1. Open Ms. Excel. Go to Data tab, the select From Access.

2. Locate the database path in the dialog box.

3. In the pop up menu, choose the table to be imported. Then choose the table type.

4. Wait until the table is show up in the spreadsheet. And you are done with linking.

Linked Ms Excel Spreadsheet

Next, we’re linked the Ms Excel spreadsheet with the Ms Access database.

1. Open the Ms Access. Then, open the database that has just been imported in previous instructions.

2. Go to External Data tab, then, click Excel in Import & Link.

3. In the pop up menu, locate the new spreadsheet. Then in the option below, choose Link to data source by creating a linked table. Then click ok.

4. Choose the sheet to be linked. Hit next.

5. Lastly, rename the new linked table before hit the Finish button.

6. You are done! Now, there will be a new table that linked to Excel spreadsheet. Every time you update the data in Ms Excel, it will automatically updated to the Access database.

Link Database in Query

Note: If you have query, form or report using the excel database, you need to link the database in the query. To link the database, follow this steps:

1. Create the new query, then rename and save it.

2. Insert both tables: the original table and the linked excel table.

3. In Query Design, linked both table by the primary key.

4. Then in the box below, select the primary key from the original table. In Update To field, input the syntax: [ExcelTableName]![ColumnName]

Example: [TransactionExcel]![TransactionID]

The ExcelTableName is the linked excel table name, while the column name is the field name from the linked Excel table.

5. Then run the query. Now, every time you update the Excel spreadsheet, it will automatically not only update the database in the linked database, but the data in query, form, and report as well.

Related Access Database

  • https://database access-templates com/read/simple-church-membership-excel-database-template

Access Database Tags: #access database from excel file #auto update access database from excel #automatically update access database from excel #create access database from excel data #create access database from excel file #populate access database from excel form #update access database from excel cell #update access database from excel example #update access database from excel form #update access database from excel graph #update access database with excel data #update an access database from excel

  • «
  • Facebook
  • Twitter
  • Pin it
  • »
  • Remove From My Forums
  • Question

  • Hi,

    Can anybody provide a sample code on how to read data from excel sheet and update an sql table.

    thanks for your kind assistance

Answers

  • How to import data from Excel to SQL Server

    This KB article demonstrates how to import data from Microsoft Excel worksheets into Microsoft SQL Server databases by using a variety of methods step by step.


    The samples in this article import Excel data by using:

    SQL Server Data Transformation Services (DTS)
    Microsoft SQL Server 2005 Integration Services (SSIS)
    SQL Server linked servers
    SQL Server distributed queries
    ActiveX Data Objects (ADO) and the Microsoft OLE DB Provider for SQL Server
    ADO and the Microsoft OLE DB Provider for Jet 4.0

    Additionally, about reading data from Excel, please check this thread.

    You need to add reference the excel object library in the COM tab to your project.

      this.openFileDialog1.FileName = «ExcelFile.xls»;
      if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
       {
          Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open( openFileDialog1.FileName, 0, true, 5, «», «», true, Excel.XlPlatform.xlWindows, «t», false, false, 0, true); 
         Excel.Sheets sheets = theWorkbook.Worksheets;
         Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
         for (int i = 1; i <= 10; i++)
         {
         Excel.Range range = worksheet.get_Range(«A»+i.ToString(), «J» + i.ToString());
         System.Array myvalues = (System.Array)range.Cells.Value;

         string[] strArray = ConvertToStringArray(myvalues);
         }
    }

  •  There are several ways to work with Excel files

    1. Use Jet OLEDB Provider. Jet Oledb provider allows to query and update/insert data inside of Excel files without using Excel. But it has some limitations when it does not recognize dates properly in some cases and returns NULL values for some cells if column inside of the spreadsheet has mixed types of data.

    2. Use Microsoft Office Tools for .NET. This way is slower, but gives you more functionality and returns proper data type for each cell. You need to pay attention to releasing all the resources associated with it, because it is COM-based.

    3. Use third party components that could provide desired functionality. I, personally, created my own component to output data into Excel without using Jet or any other tools, just because none of them met my performance requirements.

    Following are some links with the samples

    http://support.microsoft.com/kb/306022/en-us

    http://support.microsoft.com/kb/326548/en-us

    http://support.microsoft.com/kb/307029/en-us

  • Yes, you can and those blank cells would produce NULL values. You could write your own code for the export or to use SQL DTS services


Содержание

  1. Updating SQL Tables from Excel
  2. Interested in exciting thought leadership and revenue insights?
  3. 1. ExecuteSQL
  4. 2. Connection
  5. 3. SQLStatement
  6. 4. TableSheet (Optional)
  7. 5. Table (Optional)
  8. XL3RunSQL
  9. How to Update an SQL Table from Excel
  10. End users love working in Excel
  11. How to Update an SQL Table from Excel
  12. Let your non-technical users update and manage the SQL Server data
  13. Assured Data Quality
  14. Automatic Lookup of key values from other tables
  15. Familiar and User-friendly Excel Interface
  16. A Low-Stress Solution with High Value to Your Organization
  17. Try SQL Spreads First-Hand to Take Control of your SQL Server Data Management
  18. Johannes Åkesson
  19. Insert, Update or Delete Data in SQL Server from Excel
  20. Prerequisites
  21. OPENROWSET Examples
  22. SELECT with a JOIN and ORDER BY Clause
  23. INSERT with a SELECT Statement
  24. UPDATE with a JOIN Statement
  25. DELETE with a JOIN Statement
  26. General Analysis

Updating SQL Tables from Excel

Interested in exciting thought leadership and revenue insights?

Sign up for the Fluence newsletter.

Most of our customers use XLCubed for reporting, analysis and data visualisation, but an increasing number use it for data updates, either within budgeting and forecasting solutions or in niche applications.

XL3RunSQL is a neat method for running SQL updates from Excel, and allows users to build input forms (which can ultimately be web-enabled) quickly and easily.

In this blog, we will walk through the steps to set this up.

Here’s an XLCubed Table based on a SQL query, showing employee details including their salary and commission:

We will use an XL3RunSQL formula to change and update each employee’s salary and commission.

Columns P and Q will hold the new values for commission and salary that will be used to update the table:

The XL3RunSQL Formula has the following syntax:

=XL3RunSQL(ExecuteSQL, Connection, SQLStatement, [TableSheet], [Table])

To set up the parameters for each row to be used in the XL3RunSQL statement, add four calculations to the tables in columns K-N. We will then add some formulas to manage the update. Adding these to the table means that data growth is handled automatically.

The parameters are set up as follows:

1. ExecuteSQL

A cell reference that contains TRUE when the SQL Statement should be run. After execution, the cell reference will be set to FALSE or an error message if an error occurred.

We will create an XL3Link in column N so that when clicked, it will update a certain cell reference to TRUE, allowing the XL3RunSQL to run the SQL statement. Use the following formula:

This will set the cell L4 to TRUE only when there are new values in columns P and Q – this ensures the SQL query is only run when new values have been added.

2. Connection

The connection to use to connect to the database. This is normally the Connection ID of a workbook relational connection or a connection string.

From the XLCubed Ribbon > Connections:

3. SQLStatement

The SQL Statement to run.

We have set up the SQL statement in column K using a CONCATENATE formula:

=CONCATENATE(“update employees set salary = “, TEXT(IF($P4=””,$I4, $P4),0),”,commission_pct=”, TEXT(IF($Q4=””,$J4,$Q4),”0.00″), “where employee_id = “, TEXT($B4,0),””)

This formula will set the SQL Statement to update the salary and the commission to the new values. В If there are no new values, the SQL statement will not run and the values will remain unchanged.

4. TableSheet (Optional)

Worksheet name containing query table or XLCubed Table to refresh after the SQL has run.

5. Table (Optional)

The name of the query table or XLCubed Table to refresh after the SQL has run.

We can name the table by right-clicking on the table > XLCubed Properties > Behaviour

XL3RunSQL

We now have the parameters we need to set up the XL3RunSQL forumla.

We will set up our formula in column M:

Now we can see that every time we add values for the New Salary or New Commission, the table will update every time we click ‘Update’. We can also hide the calculation columns K-M to make the table look neater and not show any unnecessary information.

After we have input all of our data and updated the table, we can then clear the data in columns P and Q . This can be done using an XL3link, for example:

To make the range dynamic, you could also use a named range for both columns P and Q.

In the example below I have used a slicer to filter the information based on a specific Job Type. As you can see, since the formulae are included as Table calculations, the whole input table handles varying number of rows without the need for any manual copying of formuale.

To utilise the same approach with stored procedures, the XL3RunSQLProc formula has a similar logic.

Источник

How to Update an SQL Table from Excel

If you want to easily let your non-technical users update and manage SQL Server data from Excel,click here to download the SQL Spreads Excel Add-In.

SQL Spreads solves some common data management problems for Microsoft SQL Server. It makes it fast and simple to update an SQL table from an Excel spreadsheet. And it gives you the control you need to manage data entered by various users on a collaborative team.

End users love working in Excel

End users love working in Excel. They know the tool, and they are free to do what they want. That’s the heart of the much-loved Excel application, but also the start of problems for the people taking care of the data. The freedom to add cells and enter “whatever-you-like” values causes huge problems when trying to store and summarize the data in a structured way.

Updating or collecting some “not-available-in-our-systems” data from colleagues is often done by mailing out some Excel file or putting a spreadsheet on a file share.

When users update data in an Excel spreadsheet that should be saved or update in an SQL table, problems like these usually occur:

  • Cells in the spreadsheet can contain invalid data types.
  • There will be problems when users change the layout of the sheet.
  • Difficulties to keep track of previous versions of the Excel spreadsheet.
  • Hard to track who has changed a specific value in a sheet.
  • Troublesome to extract Excel data (with a tool such as SSIS).
  • There can be a delay of several hours between when a user enters the figures and when they appear in the database.

In finance, IT and other fields, structured data is a vital part of the operations. In those fields, you can — literally in minutes — let your end-users update data in structured SQL tables themselves – using Excel. No coding experience or extensive training is necessary.

Here’s information on how you can use SQL Spreads, an Microsoft Excel Add-In, to efficiently and accurately update an SQL Server database from Excel. I will show how to easily bring in your SQL Server tables into Excel for easy updating/management. Then show you how to share the document with your end users and how to keep track of data quality.

How to Update an SQL Table from Excel

To set up an Excel document to work with the data in an SQL Server table, follow these few simple steps:

  1. Download and install the SQL Spreads Excel Add-In.
  2. Go to the SQL Spreads tab in Excel and select Design mode.
  3. A list of databases will appear on the right. Chose the database you are using and select an SQL table to update from Excel.
  4. From the Columns tab you can fine-tune how your table is presented in Excel. You can select the columns you want to update, rearrange them into the order you prefer, and change their names if desired.
  5. When you finished fine-tuning your table, go to the spreadsheet and start updating the data from SQL Server. When you press the Save button the changes will be saved back to your SQL Server table.

There are also several other great benefits of the Designer to easily connect an Excel spreadsheet to a table in SQL Server. For example:

  • Set which columns are editable and which are “read-only”
  • Select which rows in the database are loaded into the Excel spreadsheet
  • Enable Change Tracking and the application will then insert the date and time when a row is changed, as well as the user making the change.
  • Show drop-down lists where the user can select a readable text instead of a key value for columns relating to other tables.

Let your non-technical users update and manage the SQL Server data

After you exit the Design mode you can share your Excel document like any other Excel file. All the settings will follow the document and other users can use your Excel file to update the SQL tables from Excel.

But maybe one of the biggest benefits of SQL Spreads is its ease of use. And the benefits are not only for administrators but also for authorized users throughout your business or enterprise. Non-technical users can use SQL Server-connected Excel documents that you create and share with them. The result will be an accurate and effective collaboration with safeguards including built-in conflict detection.

Assured Data Quality

To get the highest possible quality of data, SQL Spreads uses several methods to guarantee the validity of the entered data:

  • When figures are entered, they are validated against the types of the database columns, and the user receives immediate feedback.
  • Each changed row is tracked in the database to see when a row was changed and by who.
  • A built-in conflict detection system enables safe and easy collaboration.
  • When sharing the document with others, they can be given an Editor role to disable the Design mode to protect the Excel sheet set up that you’ve created.

Automatic Lookup of key values from other tables

Databases contains relations, and a table with keys relating to other tables can be hard to update manually.

When updating a SQL Server table from within Excel, SQL Spreads can lookup those key values in other tables and show drop-down lists where the user can select a readable text instead of a keys value. When the changes are saved to the database, the looked up key will be saved to the database.

Familiar and User-friendly Excel Interface

The data in SQL Server tables can be directly updated from Excel. Users are authenticated using their Windows Login and can only work with the Excel documents for which they are authorized.

Data is automatically validated when users enter their figures through SQL Spreads. And data from other Microsoft Excel documents can be pasted directly into the SQL Server connected documents.

A Low-Stress Solution with High Value to Your Organization

With SQL Spreads, you can:

  • Use Excel to work with data in SQL Server tables.
  • Let non-technical users work with the SQL Server data.
  • Ensure that the entered data is valid.

But more far-reaching benefits can be offered to your business or enterprise by using SQL Spreads. You will immediately see time savings across the board.

  • First, the setup is really fast and simple.
  • Second, when end-users enter data, SQL Spreads will guide them through the right way to enter the data.
  • Third, data owners will have the advantage of being able to easily access centralized data through Excel.
  • Fourth, you can put an end to struggling with importing Excel data using SSIS or maintaining VBA scripts.
  • Lastly, no more troubleshooting and correcting problems created by users altering the spreadsheet.

Those time-consuming processes and frustrations are replaced by SQL Spreads with fast, reliable data management.

Try SQL Spreads First-Hand to Take Control of your SQL Server Data Management

Try SQL Spreads by downloading the new SQL Spreads trial from this page.

There is also a demo video available showing how you can use SQL Spreads to create an Excel document to update the SQL table from Excel.

Editors note: This blog post was originally published for a previous version of SQL Spreads and has been completely revamped and updated for accuracy and comprehensiveness.

Johannes Åkesson

Worked in the Business Intelligence industry for the last 15+ years.

Founder of SQL Spreads – the data management
solution to import, update and manage
SQL Server data from within Excel.

Источник

Insert, Update or Delete Data in SQL Server from Excel

Problem

I have seen your previous tips (Export data from SQL Server to Excel and Different Options for Importing Data into SQL Server) related to working with Excel and SQL Server data. The main command used in one of the tips is OPENROWSET. This has been beneficial for us because in our environment because our business users provide data to us in the form of Excel spreadsheets. Many of the situations end up translating to INSERT, UPDATE or DELETE code in one or more of our SQL Server databases. We always upload the data to a table and then begin the process. Although this process works are you familiar with any other options to directly perform the INSERT, UPDATE or DELETE operations? Are their any benefits to transitioning our code to another approach with the OPENROWSET command?

Solution

Yes — You are correct the OPENROWSET command can directly support INSERT, UPDATE or DELETE operations as shown in these tips: Export data from SQL Server to Excel and Different Options for Importing Data into SQL Server. In addition, the OPENROWSET command can also support SELECT statements where a table is joined to the Excel spreadsheet. Let’s work through some examples with the SQL Server 2005 AdventureWorks sample database for each operation with a sample Excel spreadsheet.

Prerequisites

For all of these examples, please do the following:

  • Download this Excel (Office 2003) spreadsheet to perform the operations.
  • In order to follow the examples, be sure to save the Excel spreadsheet into a directory called C:MSSQLTips.
  • Review each of the worksheets in the Excel file to see the different data.
  • Be sure to close the Excel spreadsheet before running any of the code.
  • Review each of the commands below before executing them in your environment.

OPENROWSET Examples

Below are four examples to show some of the flexibility with the OPENROWSET command:

SELECT with a JOIN and ORDER BY Clause

Code Explanation — With the query below, 5 records should be returned to show a simple INNER JOIN statement can return a single result set from both data in the table ([Sales].[SalesPerson]) and Excel spreadsheet.

INSERT with a SELECT Statement

Code Explanation — With the first block of code, five records are inserted into the [AdventureWorks].[Sales].[SalesPerson] table by reading the data from the INSERT_Example worksheet of the Excel spreadsheet. In the second query, the data inserted is verified.

UPDATE with a JOIN Statement

Code Explanation — With the first block of code, five records are updated in the [AdventureWorks].[Sales].[SalesPerson] table by reading the data from the UPDATE_Example worksheet of the Excel spreadsheet. In the second query, the data updated is verified.

DELETE with a JOIN Statement

Code Explanation — With the first block of code, five records are deleted in the [AdventureWorks].[Sales].[SalesPerson] table by reading the data from the DELETE_Example worksheet of the Excel spreadsheet. In the second query, the data deleted is verified.

General Analysis

In terms of transitioning your code to the new approach, I have yet to experience any performance issues with 1000’s of records, but that seems to be the first concern. If you test the approach and the overall performance is not an issue, then consider the approach. It also may be faster to perform a single UPDATE as is the case with the example above versus uploading (INSERT. SELECT) the data and then performing an UPDATE based on the new table. In addition, by using the commands listed above versus a two step process the overall code may be a little bit cleaner. A second consideration with SQL Server 2005 is that the Surface Area Configuration setting must be enabled to use this code in either case. Finally, with either approach be sure to clean up any Excel spreadsheets or temporary tables once you are finished with them.

Источник

Like this post? Please share to your friends:
  • Update all references in word
  • Update all links in excel
  • Unhiding a sheet in excel
  • Update all formulas in excel
  • Unhide one row in excel