Solved

reference to an Excel cell in an SQL Command text

Posted on 2014-04-08
7
178 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
  • 2
7 Comments
 
LVL 42

Expert Comment

by:EugeneZ
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 500 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Slow Connectivity over ODBC 8 38
sql server concatenate fields 10 36
Help Required 3 97
SQL - Use results of SELECT DISTINCT in a JOIN 4 23
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

832 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