Exporting a TEXT (or long varchar) column to an Excel file with the OPENROWSET command.

  • Hi,

    I'm using the OPENROWSET command to export data from a table into an Excel file. I'm using this command because I need to create a dynamic command string - which can't be achieved by the native SSIS tools, for example.

    The problem is that when I'm exporting anything with more than 255 characters, the export fails.

    One solution that seems to solve the problem is a dummy row with more than 255 chars. Any how - I don't realy want to use this method.

    Any idea how to overcome this?

    A sample export script:

    INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=c:\junk\EPPlusFile.xlsx;HDR=YES;IMEX=1"',

    'SELECT [accountno], CREATEON, NOTES FROM [CONTACT1$]')

    SELECT [accountno], CREATEON, NOTES FROM CONTACT1

  • What this boils down to is a data type problem. I'm not aware of another solution, but have you Googled it ? SSIS uses what it knows about Excel unless the spreadsheet itself can indicate otherwise, and from SSIS's point of view, an empty Excel column has a data length of 255 characters, and I'm not aware of any way to change that behavior. If you find another solution, please post it, as you won't be the only one that wants to know.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Not sure what you mean about SSIS not being able to do a "dynamic command string". It can do dynamic connections, and dynamic queries.

    But the main thing you're running into is that Excel isn't really designed for large text data. Does the target file need to be Excel?

    Per Microsoft, Excel 2010 can only go up to a specific number of characters in a single cell. Details here: http://office.microsoft.com/en-ca/excel-help/excel-specifications-and-limits-HP005199291.aspx

    32,767 characters. Only 1,024 display in a cell; all 32,767 display in the formula bar.

    Max column width is 255 characters.

    Edit: Correct Excel limits.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • SSIS is indeed able to compose dynamic strings (you just use programmatic tools inside ssis, so again, its not really the native tools). I meant that there is not way to output into excel dynamically with the native ssis tools.

    I'm aware of the limitations of Excel. Thank you for the reply. 🙂

    I eventually used .NET code and created a small program that creates and gets the data into an excel file (using the EPPlus library). 🙂

  • idogal (12/18/2012)


    SSIS is indeed able to compose dynamic strings (you just use programmatic tools inside ssis, so again, its not really the native tools). I meant that there is not way to output into excel dynamically with the native ssis tools.

    I don't think you need any tool for this as this can be achieve by setting expressions with the help of some variable declaration.

  • There is no way to export dynamic input into an excel file with the DFT tools. If someone can prove otherwise, I would be happy to learn.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply