Problem using expression in SSIS

  • mohanbabu.s - Sunday, November 11, 2018 4:47 PM

    I am getting this error when i try to evaluate the expression itself.  Ideally it should give this error during run time right?

    SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1))          

    Above is the expression. @[User::var_filename] is the result of for each file enumerator.  I even used the conditional expression check for non zero value from findstring function and only if its greater than zero executing above substring function.  Something like below. 

    (FINDSTRING(@[User::var_filename],"_0", 1) > 0 ? SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1)) : @[User::var_filename] . 

    For above expression, why is that i am getting error in the expression editor itself while evaluating it.

    I believe it is evaluating the expression during design time. I even set Evaluate as Expression to False.  My variable field has "f1_sypar_ctl_00001-00001" and I need to extract only f1_sypar_ctl.  

    Kindly advice!!

  • mohanbabu.s - Sunday, November 11, 2018 6:49 PM

    mohanbabu.s - Sunday, November 11, 2018 4:47 PM

    I am getting this error when i try to evaluate the expression itself.  Ideally it should give this error during run time right?

    SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1))          

    Above is the expression. @[User::var_filename] is the result of for each file enumerator.  I even used the conditional expression check for non zero value from findstring function and only if its greater than zero executing above substring function.  Something like below. 

    (FINDSTRING(@[User::var_filename],"_0", 1) > 0 ? SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1)) : @[User::var_filename] . 

    For above expression, why is that i am getting error in the expression editor itself while evaluating it.

    I believe it is evaluating the expression during design time. I even set Evaluate as Expression to False.  My variable field has "f1_sypar_ctl_00001-00001" and I need to extract only f1_sypar_ctl.  

    Kindly advice!!

    My bad. I missed to initialize the variable @[User::var_filename]. Otherwise you will get error during design time.  Thanks a lot for trying to help me.

  • Just curious - why do all of this when you could use TOKEN instead?

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeffrey Williams 3188 - Sunday, November 18, 2018 7:56 AM

    Just curious - why do all of this when you could use TOKEN instead?

    TOKEN was introduced only in 2012.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin - Sunday, November 18, 2018 9:07 AM

    Jeffrey Williams 3188 - Sunday, November 18, 2018 7:56 AM

    Just curious - why do all of this when you could use TOKEN instead?

    TOKEN was introduced only in 2012.

    Didn't even realize this was 6 years old...

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • mohanbabu.s - Sunday, November 11, 2018 10:16 PM

    mohanbabu.s - Sunday, November 11, 2018 6:49 PM

    mohanbabu.s - Sunday, November 11, 2018 4:47 PM

    I am getting this error when i try to evaluate the expression itself.  Ideally it should give this error during run time right?

    SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1))          

    Above is the expression. @[User::var_filename] is the result of for each file enumerator.  I even used the conditional expression check for non zero value from findstring function and only if its greater than zero executing above substring function.  Something like below. 

    (FINDSTRING(@[User::var_filename],"_0", 1) > 0 ? SUBSTRING (@[User::var_filename],1, (FINDSTRING(@[User::var_filename] ,"_0", 1)-1)) : @[User::var_filename] . 

    For above expression, why is that i am getting error in the expression editor itself while evaluating it.

    I believe it is evaluating the expression during design time. I even set Evaluate as Expression to False.  My variable field has "f1_sypar_ctl_00001-00001" and I need to extract only f1_sypar_ctl.  

    Kindly advice!!

    My bad. I missed to initialize the variable @[User::var_filename]. Otherwise you will get error during design time.  Thanks a lot for trying to help me.

    I hit a another problem with same expression.   
    var_FileName_Fmt = FINDSTRING( @[User::var_filename] ,"_0",1) == 0 ? (SUBSTRING( @[User::var_filename] ,1,50)) : (SUBSTRING ( @[User::var_filename] ,1, (FINDSTRING( @[User::var_filename] ,"_0", 1)-1)))

    var_filename is  the name of the file from 'for each loop file' enumerator and also initialized to f1_sypar_ctl_0000100001_20181112_140611.  This was perfectly working fine if the file name is f1_sypar_ctl_0 i.e file name having '_0' in it.  But not for files like  f1_sypar_ctl.  

    If it satisfy the above conditional expression expression it is always taking the default value for var_filename as set in the variable editor.  I even changed the condition check for > 0 , < 0 etc., Also find string returns 0 if the file name doesn't have _0 in it. 

    I am really puzzled why its not taking the value of file name from for each loop enumerator no matter whether the file name has '_0' in it or not.   I checked the option of evaluation as expression for these variables but still same problem. 

    Please help!!

  • I suggest that you create a new variable, with the expression
    FINDSTRING( @[User::var_filename] ,"_0",1)

    And then set a breakpoint on the first task in your foreach loop.
    Run the package and check the Locals window to determine the runtime value of the above expression. This should remove any doubt as to what is going on here.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin - Wednesday, November 21, 2018 5:25 AM

    I suggest that you create a new variable, with the expression
    FINDSTRING( @[User::var_filename] ,"_0",1)

    And then set a breakpoint on the first task in your foreach loop.
    Run the package and check the Locals window to determine the runtime value of the above expression. This should remove any doubt as to what is going on here.

    Thanks Phil for your reply.  But I have spent more time on this.  It is always evaluating the substring statement with -1 in the length and throws the error during run time and later it picks the default value. 
    Decided to go with Token and it works out well for me.  Some one in the message, suggested to use it.   I would like to thank him.

  • mohanbabu.s - Wednesday, November 21, 2018 11:15 PM

    Phil Parkin - Wednesday, November 21, 2018 5:25 AM

    I suggest that you create a new variable, with the expression
    FINDSTRING( @[User::var_filename] ,"_0",1)

    And then set a breakpoint on the first task in your foreach loop.
    Run the package and check the Locals window to determine the runtime value of the above expression. This should remove any doubt as to what is going on here.

    Thanks Phil for your reply.  But I have spent more time on this.  It is always evaluating the substring statement with -1 in the length and throws the error during run time and later it picks the default value. 
    Decided to go with Token and it works out well for me.  Some one in the message, suggested to use it.   I would like to thank him.

    FINDSTRING can't return a value lower than 0; this means that the value of the FINDSTRING expression is always evaluated to 0 and then has 1 subtracted from it somewhere else in your expression.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A - Thursday, November 22, 2018 1:42 AM

    mohanbabu.s - Wednesday, November 21, 2018 11:15 PM

    Phil Parkin - Wednesday, November 21, 2018 5:25 AM

    I suggest that you create a new variable, with the expression
    FINDSTRING( @[User::var_filename] ,"_0",1)

    And then set a breakpoint on the first task in your foreach loop.
    Run the package and check the Locals window to determine the runtime value of the above expression. This should remove any doubt as to what is going on here.

    Thanks Phil for your reply.  But I have spent more time on this.  It is always evaluating the substring statement with -1 in the length and throws the error during run time and later it picks the default value. 
    Decided to go with Token and it works out well for me.  Some one in the message, suggested to use it.   I would like to thank him.

    FINDSTRING can't return a value lower than 0; this means that the value of the FINDSTRING expression is always evaluated to 0 and then has 1 subtracted from it somewhere else in your expression.

    Hi Thom, 

    Thanks for your reply.  Findstring function returns 0 if no match is found in the string.  In that case i am not evaluating the substring function with -1 in the length parameter.  Its very strange why it is getting executed even when find string returns 0.  I checked the value of findstring function in another variable and its zero.  If its zero it should execute SUBSTRING( @[User::var_filename] ,1,50). 

    FINDSTRING( @[User::var_filename] ,"_0",1) == 0 ? (SUBSTRING( @[User::var_filename] ,1,50)) : (SUBSTRING ( @[User::var_filename] ,1, (FINDSTRING( @[User::var_filename] ,"_0", 1)-1)))

Viewing 10 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic. Login to reply