?
Solved

reference to an Excel cell in an SQL Command text

Posted on 2014-04-08
7
Medium Priority
?
415 Views
Last Modified: 2016-06-04
How I can reference to an Excel cell in an SQL Command text? Getting  'error converting data type varchar to uniqueidentifier'

exec sp_executesql N'SELECT CustomFieldEntryView.* FROM CustomFieldEntryView WHERE (DataResourceId = @DataResourceId)',N'@DataResourceId uniqueidentifier',@DataResourceId = Sheet1!$C$2
0
Comment
Question by:prfraczek
[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
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Eugene Z
ID: 39991141
please clarify what you try to do.


if you plan to query Excel from sql server
you can set linked server:

How to use Excel with SQL Server linked servers and distributed queries
http://support.microsoft.com/kb/306397


or use OPENROWSET
http://technet.microsoft.com/en-us/library/ms190312.aspx
 for example:
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
         'Excel 12.0;Database=c:\test.xls;HDR=YES',
         'SELECT * FROM [Sheet1!$C$2])
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39991528
Where does your command run - on sql server, in Excel VBA, or in standalone application?
0
 

Author Comment

by:prfraczek
ID: 39991538
excel Data-From other Sources- Microsoft query-SQL Command text
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 2000 total points
ID: 39991985
In excel, you have to design the query with parameter(s).

http://office.microsoft.com/en-us/excel-help/use-microsoft-query-to-retrieve-external-data-HA010099664.aspx?CTT=1

Then, in the worksheet, you'll be able to tell that the value of the parameter should be taken from C2.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

718 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