question

InwoodGuy avatar image
InwoodGuy asked

SSIS Dervied Column

Why is this expression not working in SSIS Dervied COlumn Trans;

right('000'+convert(nvarchar,columnname),12)

sql-server-2005ssis
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jay Bonk avatar image
Jay Bonk answered

NVARCHAR isn't recognized in SSIS, in the derived column expression, try this:

RIGHT("000" + (DT_WSTR,30)column_name,10)

NVARCHAR is Unicode in SQL Server, DT_WSTR in SSIS

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image
Fatherjack answered

The NVARCHAR needs a length after it. NVARCHAR(30) would accommodate a 30 character length string, use something at least the size of the column you are converting. Use RIGHT('000'+CONVERT(NVARCHAR(30),columnname),12) e.g.

use adventureworks
go 
select right('000'+convert(nvarchar(30),humanresources.employee.NationalIDNumber),10)
from humanresources.employee
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

InwoodGuy avatar image
InwoodGuy answered

i tired but it shows this error

TITLE: Microsoft Visual Studio

Error at Data Flow Task 1 [Derived Column [2987]]: The function "NVARCHAR" was not recognized. Either the function name is incorrect or does not exist.

Error at Data Flow Task 1 [Derived Column [2987]]: Attempt to parse the expression "RIGHT("000"+CONVERT(NVARCHAR(255), [columnname] ),12)" failed and returned error code 0xC004708A. The expression cannot be parsed. It might contain invalid elements or it might not be well-formed. There may also be an out-of-memory error.

Error at Data Flow Task 1 [Derived Column [2987]]: Cannot parse the expression "RIGHT("000"+CONVERT(NVARCHAR(255), [columnname] ),12)". The expression was not valid, or there is an out-of-memory error.

Error at Data Flow Task 1 [Derived Column [2987]]: The expression "RIGHT("000"+CONVERT(NVARCHAR(255), [columnname] ),12)" on "output column "Derived Column 1" (3038)" is not valid.

Error at Data Flow Task 1 [Derived Column [2987]]: Failed to set property "Expression" on "output column "Derived Column 1" (3038)".


ADDITIONAL INFORMATION:

Exception from HRESULT: 0xC0204006 (Microsoft.SqlServer.DTSPipelineWrap)


BUTTONS:

OK

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

what is the datatype of the column you are converting?
0 Likes 0 ·
source is nvarchar(30) I need to add leading zeros using Derived Transformation is SSIS.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.