Solved

reference to an Excel cell in an SQL Command text

Posted on 2014-04-08
7
328 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

617 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