Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Exporting a TEXT (or long varchar) column to an Excel file with the OPENROWSET command. Expand / Collapse
Author
Message
Posted Thursday, December 13, 2012 5:19 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 7, 2014 12:16 AM
Points: 8, Visits: 89
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

Post #1396131
Posted Thursday, December 13, 2012 8:29 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, July 17, 2014 1:20 PM
Points: 1,615, Visits: 2,116
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)

Internet ATM Machine
Post #1396226
Posted Thursday, December 13, 2012 9:31 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #1396257
Posted Tuesday, December 18, 2012 11:37 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 7, 2014 12:16 AM
Points: 8, Visits: 89
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).
Post #1398198
Posted Wednesday, December 19, 2012 12:32 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 19, 2013 4:30 AM
Points: 78, Visits: 195
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.
Post #1398214
Posted Wednesday, December 19, 2012 12:41 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 7, 2014 12:16 AM
Points: 8, Visits: 89
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.
Post #1398215
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse