PRECEDENCE CONSTRAINT: DATA TYPE CONVERSION ERROR

回答済み PRECEDENCE CONSTRAINT: DATA TYPE CONVERSION ERROR

  • Friday, August 10, 2012 8:06 PM
     
     

    I'm getting error for the following code:

    LEN (@[User::strFileName]) == 17&& (DT_I8)SUBSTRING(@[User::strFileName],6,2) < 13 && (DT_I8)SUBSTRING(@[User::strFileName],8,2) < 32 && DATEDIFF("dd",(DT_Date)(SUBSTRING(@[User::strFileName],6,2) + "-"+SUBSTRING(@[User::strFileName],8,2) + "-" + SUBSTRING(@[User::strFileName],10,4)),GETDATE()) > @[User::intFileMaxAge]

    Note: strFileName is String variable

    intFileMaxAge is Int32 variable

    I'm gettign following error:

    Error at constraint : Error code 0x80020005 occured attempting to convert from data type DT_WSTR to data type ST_I8

    Error at constraint :Casting expression "SUBSTRING(@[User::strFileName],6,2) from DT_WSTR to data type DT_I8 failed. 


    ZK


    • Edited by SQL_Admirer Friday, August 10, 2012 8:23 PM CHANGED SUBJECT
    •  

All Replies

  • Friday, August 10, 2012 8:41 PM
     
     

    HERE IS THE SNAP SHOT.


    ZK

  • Friday, August 10, 2012 8:48 PM
    Moderator
     
     

    How does the file name look like?

    It is most likely the issue is in the data. E.g. (DT_I8)SUBSTRING(@[User::strFileName],6,2)  cannot cast from a non-numeric value


    Arthur My Blog

  • Friday, August 10, 2012 8:51 PM
     
     

    to build an expression your variables should have a valid default values as well. The expression builder uses variable current values to evaluate the expression.

    I used "Filen010120012thisworks" as a file name.


    Please mark the post as answered if it answers your question


    • Edited by DotNetMonster Friday, August 10, 2012 8:54 PM update
    •  
  • Friday, August 10, 2012 8:52 PM
     
     

    Its like "FileName_MMDDYY.txt"

    or filename with time stamp


    ZK

  • Friday, August 10, 2012 8:55 PM
    Moderator
     
     Answered

    This helps to find out that

    SUBSTRING(@[User::strFileName],6,2) cannot be converted to INT because it is text


    Arthur My Blog

  • Friday, August 10, 2012 8:58 PM
     
     

    Its like "FileName_MMDDYY.txt"

    or filename with time stamp


    ZK

    your expression requires the date to start from 6th character, if it does not, your expression will blow a run time error. you should reconsider doing this in a "Script Task" and set a bool variable to true or false based on the validation. 

    Please mark the post as answered if it answers your question