Solved

MS SQL 2008 - Update multiple rows with different values from spreadsheet

Posted on 2015-02-15
5
161 Views
Last Modified: 2015-02-17
I have a table with about 350K rows in it and need to update about 45K with data that is in an excel spreadsheet.  The table to update is called "storage".  Fields mappings are as follows:
SHEET               STORAGE
receiptdate      sig_date
fromdate          Datefrom
todate               Dateto
alpha_from      contrfrom
aplha_to           contrto
main_desc       desc

the "where" indicator is a field common to both the spreadsheet and the table, tempid = tempid
0
Comment
Question by:RavenTim
  • 3
5 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40610958
update storage
set sig_date =receiptdate, 
DateFrom=fromdate, 
DateTo=todate, 
contrfrom=alpha_from,
contrto=alpha_to,
desc=main_desc
From storage inner join sheet on storage.tempid=sheet.tempid

Open in new window

0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 40611314
the question was almost the answer, I hope you can see the similarity

table to update is called "storage".  Fields mappings are as follows:
SHEET               STORAGE
receiptdate      sig_date
fromdate          Datefrom
todate               Dateto
alpha_from      contrfrom
aplha_to           contrto
main_desc       desc


the "where" indicator is a field common to both the spreadsheet and the table, tempid = tempid

hence you may not need to ask a similar question in future :)
no points please
0
 

Author Comment

by:RavenTim
ID: 40611393
I understand.  I guess I need to know how to "join" the excel spreadsheet.  Do I direct the join to the folder the spreadsheet is in?
0
 
LVL 18

Accepted Solution

by:
Simon earned 250 total points
ID: 40611761
The syntax I posted was intended for tables existing in database. I'd suggest you use the data import/export wizard to import the Excel sheet into a new table in your database, then run the update query as described above and finally drop the table containing the spreadsheet data.

If you want to just link the spreadsheet data, you could do that in MSAccess, by using a linked tablesfor the SQL Server table and linking the spreadsheet, but fastest and most robust method is to import the spreadsheet data into MSSQL first. You can import it to your tempdb instead of your production db if you prefer.
0
 
LVL 18

Expert Comment

by:Simon
ID: 40613537
Further thought: If you're doing this regularly, you might want to consider defining a package for it in SQL Server Integration Services (SSIS).
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now