Solved

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

Posted on 2015-02-15
5
191 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 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

734 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