Pergunta

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:

  1. Generate a CREATE TABLE string.
  2. Use that string in an Execute Sql Task with Excel CM, which creates an Excel file.
  3. Generate an INSERT INTO OPENROWSET... SELECT FROM ... command string.
  4. 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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top