Question

I have an SSIS control flow with about a dozen items and the goal of running this package is to run some update statement in SQL and then run a query to get output data and write that to an excel file. So what I have done is created a 'data flow task' at the end of my processing where I want to write to Excel. After going to the 'data flow' tab I added an OLE DB Source and set the connection as well as added a SQL Command. This SQL Command is what generates the output I want to write to Excel. There is only 1 column for output and I also mapped in the OLE DB Source.

After that I added an 'Excel Destination' object. I then created a new connection to an Excel file on our network where I want the data written. I am able to select the name of the excel sheet in the file and then I click on the 'Mappings' item. The problem is the 'Input Column' on the 'Mappings' page doesn't let me choose a field, all it has is 'ignore'.

I have tried using SSIS to create the Excel table (which didn't work) and I have also created the Excel file outside of SSIS (which didn't work), I can't figure out how to get around this.

EDIT: 1) This did create the excel table and I am able to map two fields together on the Excel Destination object BUT I have a red 'X' on the object that says: the column XXX cannot convert between unicode and non-unicode data types. I am not able to use this object as long as it has the a red 'X'. Also, on another Excel Destination object I am using I create the table the exact same way in SSIS but get a WARNING stating truncation will occur

2) I am developing in VS2008 w/SP1. The DB is SQL 2008r2. The excel file is an XLSX file and my Excel Connection Manager is set to use Office 2007.

3) The data type of the column for the connection I have with the red 'X' is DT_STR, length 50. The data type of the column for the connection I have with the WARNING is DT_WSTR, length = 306. These are read only.

Était-ce utile?

La solution

Ah... thanks, Baub -- remember in the future to post error messages... that would have made this quick and easy to answer for you:

The MS Office "engine" used, to export to Excel, only accepts Unicode text (NVARCHAR in SQL, or DT_WSTR in SSIS). It will not accept ASCII text (VARCHAR in SQL, or DT_STR in SSIS).

The easiest approach, I find, is to convert the column in T-SQL. Since you said length=50:

Column2Export = CONVERT(NVARCHAR(50), OriginalColumn)

An alternative approach is to do it in SSIS, though I think that's a lot more work. In your your Data Flow Task, you would add a Data Conversion component, in between the Source Component and Destination Component. Why that's more work: click on data types for each column... and needing to do it again if the layout ever changes. If you do the conversion in T-SQL, then SSIS can auto-detect the new column by you just recreating the source, the arrow, and the destination. The Data Conversion component is not all auto-detect.

For more information, see both answers on sister site dba.StackExchange.com:
https://dba.stackexchange.com/questions/41608/converting-non-unicode-string-to-unicode-string-ssis
(The 2nd answer there talks about the downloadable component "replacing data conversion"... but I see that as still more work than a T-SQL conversion.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top