Solved

reference to an Excel cell in an SQL Command text

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

762 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

22 Experts available now in Live!

Get 1:1 Help Now