JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
I've tested several methods...(not completely, but enough to come here for help) and I was wondering if AdHoc (OPENROWSET) statements can be used to create.
For example: I've selected data FROM an OPENROWSET AdHoc query source, (which is an excel file by the way), and now I want to export certain rows into a NEW excel file. The question is, can I use the OPENROWSET or other such AdHoc query formats to Create the new Excel file.
Right now I'm going to start on the Interop Method of creating an Excel File and hopefully once the file is made I can "Insert Into" but so far, Create Table() and Select Into won't allow me to use the AdHoc for creation of the destination. (keep getting syntax error around OPENROWSET()).
I've tried as well to follow the ADO syntax:
but that gives me an error about the schema not existing (which it doesn't) or insufficient permissions to use it.
Basically, in the end, what i need is to create an Excel file and dump a series of records from the DB into it. However, I would find anything other than a SQL statement inordinately inefficient for the transfer. If I need to Interop Create the XL file first, that's fine (i'd like not to, but i understand if its necessary) but for the transfer of records into Sheet1 I really...really want to use SQL with a SqlCommand() execution as that is the most efficient for my purposes at the moment. To loop through the records and set them 1 by 1 with Interop would be too slow and very cumbersome.
Thanks
For example: I've selected data FROM an OPENROWSET AdHoc query source, (which is an excel file by the way), and now I want to export certain rows into a NEW excel file. The question is, can I use the OPENROWSET or other such AdHoc query formats to Create the new Excel file.
Right now I'm going to start on the Interop Method of creating an Excel File and hopefully once the file is made I can "Insert Into" but so far, Create Table() and Select Into won't allow me to use the AdHoc for creation of the destination. (keep getting syntax error around OPENROWSET()).
I've tried as well to follow the ADO syntax:
VB.NET:
select * into [Excel 8.0;Database=c:\db\mydb.xls].[Sheet1] from MyTable
but that gives me an error about the schema not existing (which it doesn't) or insufficient permissions to use it.
Basically, in the end, what i need is to create an Excel file and dump a series of records from the DB into it. However, I would find anything other than a SQL statement inordinately inefficient for the transfer. If I need to Interop Create the XL file first, that's fine (i'd like not to, but i understand if its necessary) but for the transfer of records into Sheet1 I really...really want to use SQL with a SqlCommand() execution as that is the most efficient for my purposes at the moment. To loop through the records and set them 1 by 1 with Interop would be too slow and very cumbersome.
Thanks
Last edited: