Solved

Does an Excel 2007 table look like a real table to SQL Server?

Posted on 2011-02-24
4
254 Views
Last Modified: 2012-05-11
I have a named Table in Excel 2007 called ACCT_List. It's a list of account numbers. I want to use the Excel Table to join to tables in our SQL Server 2005 environment to retrieve some data about these accounts.

With VBA, I can generate a long string containing all the account numbers and then query "WHERE SQLTable.Acct in (x,x,x,x,x,x,x,x,x,x,x,x,x,....)" That works fine, but seems a bit clunky.

I was hoping I could tell my VBA code that the Excel table is an actual "table", and be able to join the Excel Table with the SQL table with an inner join clause.

Is that possible? Maybe in Excel 2010??

Thanks!
0
Comment
Question by:notawahoo2
  • 2
4 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 50 total points
ID: 34977636
What you are trying to do is not possible. The reason is that SQL Server runs the query on the server running the the SQL server query engine which does not have access to your workbook which is open on your local machine. Even if the workbook was running on the server SQL Server still would not be able to do any operations with it unless it was imported into it's own SQL Server table.

What you can do is load the data into a SQL Server table and then proceed from there. However, this seems even more troublesome than creating a query and using a simple comma separated list of values with the "IN" operator.

Excel 2010 provides no such service or function.

Kevin
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 34977638
You should be able to use the OPENROWSET() function as explained in this article: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/A_3025-Retrieving-Data-From-Excel-Using-OPENROWSET.html
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 34977643
Good points Zorvek.

notawahoo2: please note that the SQL Server needs to be able to access your Excel file somehow using that OPENROWSET function.
0
 

Author Closing Comment

by:notawahoo2
ID: 34979284
Thanks so much, very logical explanation of how it actually works!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

746 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

11 Experts available now in Live!

Get 1:1 Help Now