Solved

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

Posted on 2015-02-15
5
160 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:SimonAdept
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:
SimonAdept 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:SimonAdept
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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

705 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

19 Experts available now in Live!

Get 1:1 Help Now