SQL Server In SSIS, How to convert unicode datatype to excel column?

qco9c6ql  于 2023-10-15  发布在  其他
关注(0)|答案(3)|浏览(135)

I am working on SSIS Package to export the output data to Excel file. ( Excel Destination ).

I am running into conversion error.
Error Description : cannot convert between Unicode and non-Unicode string data types

Input Column Details

ColumnA ([DT_TEXT])
ColumnB ([DT_STR],200)

Data Conversion Output Column Details

ColumnA ([DT_TEXT])
ColumnB ([DT_WSTR],255)

How to convert Unicode datatype to excel column?

zqry0prt

zqry0prt1#

Using Derived Column Transformation

Add a derived column with the following expression

(DT_WSTR,255)[ColumnB]

When if fails you can use the Error Output to check the bad values causing the exception

Using Data Conversion Transformation

You can also achieve this using a Data Conversion transformation component. Just select the ColumnB as input and choose to convert to DT_WSTR data type with length = 255

Using Script Component

You just have to select ColumnB as Input column, add an Output column outColumnB of type DT_WSTR and length = 255. And just assign the input column to the output column inside the script.

Row.outColumnB = Row.ColumnB

Update 1 - Excel data types

Based on the following official documentation:

  • Import data from Excel or export data to Excel with SQL Server Integration Services (SSIS)
    The Excel driver recognizes only a limited set of data types. For example, all numeric columns are interpreted as doubles (DT_R8), and all string columns (other than memo columns) are interpreted as 255-character Unicode strings (DT_WSTR). SSIS maps the Excel data types as follows:

  • Numeric - double-precision float (DT_R8)

  • Currency - currency (DT_CY)

  • Boolean - Boolean (DT_BOOL)

  • Date/time - datetime (DT_DATE)

  • String - Unicode string, length 255 (DT_WSTR)

  • Memo - Unicode text stream (DT_NTEXT)

slwdgvem

slwdgvem2#

Use data conversion tool and convert DT_WSTR to DT_STR.Check this:

jw5wzhpr

jw5wzhpr3#

DT_TEXT and DT_STR from input are non-unicode and excel inputs are all unicode so your conversion is not unicode to non-unicode but non-unicode to unicode.

All your Data Conversion Output Columns (excel input) should be DT_NTEXT and DT_WSTR then.

相关问题