SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
idogal
idogal
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 109
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


sgmunson
sgmunson
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17921 Visits: 4647
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)
Smile Smile Smile
Health & Nutrition
GSquared
GSquared
SSC Guru
SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)SSC Guru (60K reputation)

Group: General Forum Members
Points: 60001 Visits: 9730
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
idogal
idogal
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 109
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. Smile

I eventually used .NET code and created a small program that creates and gets the data into an excel file (using the EPPlus library). :-)
rhythm.varshney
rhythm.varshney
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 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.
idogal
idogal
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 109
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search