Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning values within quotes from openrowset

Status
Not open for further replies.

dfwcharles

Technical User
Apr 10, 2002
36
US
I'm querying a Excel spread sheet and would like the values that are returned to be contained with qoutes.

Here's my query:

SELECT * FROM OpenRowSet
('MSDASQL', 'Driver=Microsoft Excel Driver (*.xls);DBQ=c:\test', 'SELECT column1 FROM
[sheet1$]')

I want the results like this 'column1data'

I've tried adding multiple quotes and + to the column name in the query. Depending on the number of quotes, I either get 'invalid object' or it just returns the name of the column. Sometimes it will even return the column name in quotes.

any ideas?
Thanks
Charles
 
Nevermind I got it, heres the correct query:


SELECT * FROM OpenRowSet
('MSDASQL', 'Driver=Microsoft Excel Driver (*.xls);DBQ=c:\test', 'SELECT ''''''''+column1+'''''''' FROM
[sheet1$]')

Eight quotes on each end.

 
You can also do the following.

SELECT Column1=char(39) + Column1 + char(39)
FROM OpenRowSet ('MSDASQL',
'Driver=Microsoft Excel Driver
(*.xls);DBQ=c:\test', 'SELECT column1
FROM [sheet1$]')
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top