Perhaps these links will help (in general, it seems there's no real solution, rather workarounds)
Dynamic CREATE TABLE command creates only "general" column data type (Excel connection)
-
07-12-2021 - |
题
I want to export all the tables in a DB to Excel files. The process should be dynamic, as the tables in the DB may vary.
The current process is using SSIS as follows:
- Generate a
CREATE TABLE
string. - Use that string in an
Execute Sql
Task with Excel CM, which creates an Excel file. - Generate an
INSERT INTO OPENROWSET... SELECT FROM ...
command string. - Use this string in an
Execute Sql
Task with an SQL SERVER CM.
The problem is that the created excel file column types are all "general", even though my script says otherwise.
An example CREATE TABLE
script:
CREATE TABLE `CONTACT1`
(
[ACCOUNTNO] LongText,
[COMPANY] LongText,
[CREATEON] datetime,
[CREATEAT] LongText,
)
"playing" with the data types doesn't help. For example, using VARCHAR(1000)
instead of LongText
, etc.
I've tried generating both xlsx
and xls
files.
This problem prevents me from Inserting data later on with an *INSERT INTO OPENROWSET(...) SELECT FROM ...*
command. An example INSERT INTO
script:
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=c:\\junk \\accountnoWithNoApps.xlsx;HDR=YES;IMEX=1\"',
'SELECT [accountno], [COMPANY], [CREATEON], [CREATEAT] FROM [CONTACT1$]')
SELECT [accountno], [COMPANY], [CREATEON], [CREATEAT] FROM CONTACT1
解决方案
不隶属于 StackOverflow