Solved

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

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
section a string 5 54
Sql does not recognize null value from Oracle source 8 26
Access PS SQLSERVER from powershell 1 29
Datatable / Dates ? 4 29
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

739 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