Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

From SQL-server to Excel

Posted on 2001-09-17
6
Medium Priority
?
391 Views
Last Modified: 2008-02-01
Hi All,

I am trying to write an SQL statement in the format:

SELECT * INTO <Target> FROM <Source>

which will run against an ADODB.Connection to a SQL server database.

For my Target, I am trying to use the string:

[Excel 8.0;HDR=Yes;DATABASE=C:\Temp.xls].[Sheet1]

but I'm always getting the error:

[Microsoft][ODBC SQL Server Driver][SQL Server]Specified owner name 'Excel 8.0;HDR=Yes;DATABASE=C:\Temp.xls' either does not exist or you do not have permission to use it.

There is no question that the Spreadsheet exists, and at present it's just a new workbook created on my machine by me with field names in it, so there shouldn't be any problem with permissions.

The source is just a table name in the SQL server database.

Any thoughts?

#D
0
Comment
Question by:batdan
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:miron
ID: 6487266
I am not sure about writing it as a single line syntax for an OPNEQUERY provider. I usually use
execute xp_addlinkedserver ...
-- when I do so I am required to create a user for that linked server ( when I forget to do it I get exactly same error as I read in the questiong you posted )

execute sp_addlinkedsrvlogin ...

and than using
OPENQUERY()

I am able to manipulate files using SQL Server.

Thanks
0
 
LVL 1

Author Comment

by:batdan
ID: 6487432
miron:
Thanks for the input, I am new to SQL server though and have not used anything like this before.  If you could give me an example of adding the server and using it in a query I would be grateful.

Thanks

#D
0
 
LVL 9

Expert Comment

by:miron
ID: 6487705
Actually OpenQuery is not needed. Sorry, I was thinking about index server.

sp_addlinkedserver N'Excel', N'Jet 4.0',
                   N'Microsoft.Jet.OLEDB.4.0',
                   N'C:\test.xls',
                   NULL,
                   N'Excel 8.0'
GO

sp_addlinkedsrvlogin N'Excel', false, N'sa', N'Admin', Null
GO
 
select * from Excel...sheet1$


0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 1

Author Comment

by:batdan
ID: 6487894
Thanks miron.  I have this working well now.  Full points for a decent alternative (which I shall award shortly)...although unfortunately I have now another problem.  I wanted to use this other server to insert data straight into the table using :

SELECT * INTO Excel...Sheet1$ FROM Customer

I don't seem to be able to do this (although I can use a normal INSERT for just one row) due to an object qualifier limitation (of 2).  I am now thinking that this is probably tough luck, and can't be done...have you come across this before, or know any way around it?

Obviously extra points will be awarded for anything useful.

Cheers

#D
0
 
LVL 9

Accepted Solution

by:
miron earned 600 total points
ID: 6488203
Have you tried it

insert into Excel...Sheet1$ SELECT * FROM Customer

or with complete insert / select list

insert into Excel...Sheet1$ ( col1, col2, ... coln )SELECT col1, col2, ... coln FROM Customer
0
 
LVL 1

Author Comment

by:batdan
ID: 6489826
Aha!

That's solved it.  Many thanks miron.

#D
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

916 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