tags:

views:

111

answers:

3

Hi

I need to assign a formatted date to a column in a data flow. I have added a Derived shape and entered the following expression for a NEW column - Derived Column = "add as new column":

"BBD" + SUBSTRING((DT_WSTR,4)DATEADD("Day",30,GETDATE()),1,4) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),6,2) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),9,2)

The problem is that the "Derived Column Transformation Editor" automatically assigns a Data Type of "Unicode string[DT_WSTR]" and a length of "7". Howver, the length of a string is 11, therefore the following exception is thrown each time:

[Best Before Date [112]] Error: The "component "Best Before Date" (112)" failed because truncation occurred, and the truncation row disposition on "output column "Comments" (132)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.

Does anyone know why the edit is insisting on a length of 7? I don't seem to be able to change this.

Many thanks,

Rob.

A: 

Are you replacing your existing field, and is that field possibly 7 chars long? The thing with the Derived Column Transform is that you can't change the field types (including length) of the existing fields.

Try to add a new field instead.

If that's not working, try adding an explicit cast around the whole expression.

(DT_WSTR,11)("BBD" + SUBSTRING((DT_WSTR,4)DATEADD("Day",30,GETDATE()),1,4) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),6,2) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),9,2))
Valentino Vranken
No, I have <Add as new Column> set
Rob Bowman
I see. How about adding an explicit cast around the whole expression?(DT_WSTR,11)("BBD" + SUBSTRING((DT_WSTR,4)DATEADD("Day",30,GETDATE()),1,4) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),6,2) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),9,2))
Valentino Vranken
BTW: SSIS knows the DATEPART function which can be used instead of those SUBSTRINGs: http://msdn.microsoft.com/en-us/library/ms137586.aspx
Valentino Vranken
A: 

What release and service pack of SQL are you using?

I just tried this on my machine and had no problems changing the result size from 7 to 11. Is it possible that you have not installed all the service packs?

William Anderson
In SQL 2008 you can no longer change the data type manually, you need to explicitly cast it to whatever you need.
Valentino Vranken
A: 

I can't understand why SSIS is measuring that column as only resulting in a seven character field - but to force it to provide an 11 character column for it, modify your expression slightly to this:

(DT_WSTR, 11)("BBD" + SUBSTRING((DT_WSTR,4)DATEADD("Day",30,GETDATE()),1,4) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),6,2) + SUBSTRING((DT_WSTR,2)DATEADD("Day",30,GETDATE()),9,2))

Todd McDermid
Hi Todd, I think that's what I said in my earlier comment.Regarding the default length of 7: I did notice that the first concatenation (the 3-char string plus the first substring) results in 7 chars.@Rob: could it be that you initially had a different expression for that field, resulting in 7 characters?
Valentino Vranken

related questions