Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-02-15
5
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 49

Assisted Solution

by:PortletPaul
PortletPaul earned 1000 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 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

722 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