none
SSIS Expression with date field RRS feed

  • Question

  • Can not pass date through expression

    @[User::InputPath] + " " +  @[User::ArchDir] +  " " + @[User::varMailTo] + " " + @[User::MaxDate]

    The data types "DT_WSTR" and "DT_DATE" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.

    Attempt to set the result type of binary operation "@[User::InputPath] + " " + @[User::ArchDir] + " " + @[User::varMailTo] + " " + @[User::MaxDate]" failed with error code 0xC0047080.

    I changed it to what's below and get

    @[User::InputPath] + " " +  @[User::ArchDir] +  " " + @[User::varMailTo] + " " + (DT_WSTR, 10) @[User::MaxDate]

    A truncation occurred during evaluation of the expression.

     (Microsoft.DataTransformationServices.Controls)

    Tuesday, December 5, 2017 6:45 PM

Answers

  • Hi Seeker of Wisdom,

    What is the value (examples) for the MaxDate when it brakes?

    But looks like you need to use this expression:

    @[User::InputPath] + " " +  @[User::ArchDir] +  " " + @[User::varMailTo] + " " + (DT_WSTR, 50) @[User::MaxDate] 

    the size / length of the converted date does not have to be so small


    Arthur

    MyBlog


    Twitter

    Tuesday, December 5, 2017 7:21 PM
    Moderator

All replies

  • Hi Seeker of Wisdom,

    What is the value (examples) for the MaxDate when it brakes?

    But looks like you need to use this expression:

    @[User::InputPath] + " " +  @[User::ArchDir] +  " " + @[User::varMailTo] + " " + (DT_WSTR, 50) @[User::MaxDate] 

    the size / length of the converted date does not have to be so small


    Arthur

    MyBlog


    Twitter

    Tuesday, December 5, 2017 7:21 PM
    Moderator
  • You may want to convert your date to a string within another variable first, that way you can also play with its format to get it how you want. (doesn't have to be in another variable, that just helps simplify the process)
    Tuesday, December 5, 2017 7:27 PM
  •    

    Arthur @[User::InputPath]+" "+@[User::ArchDir]+" "+@[User::varMailTo]+" "+(DT_WSTR,50)@[User::MaxDate]worked it evaluated as '12/5/2017 10:35:47 AM'.  I like RyanAB's answer also as I can format the date as '12/5/2017'. For Rayans answer I did have to create a variable called strMaxDate and a new scripttask with on line of code.  

    Dts.Variables("strMaxDate").Value = CStr(Dts.Variables("MaxDate").Value)


    Tuesday, December 5, 2017 8:58 PM