|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 3:26 AM
Points: 34,
Visits: 236
|
|
Hi,
Below is the expression i am trying to make work :
substring ("Archive_Full_20120731200002",1, (FINDSTRING( "Archive_Full_20120731200002","Full_", 1)-2))
Whe I use the exact string(Archive_Full_20120731200002) , I get the required result i.e Archive But when I use a variable which contains th same string, the above expression gives the error that Substring can allow -ve integer values( Here -2)
Please help me in this regard. I need to use a variable here and get it work.
Your help is appreciated!!!
Thanks Devesh
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 4,234,
Visits: 9,470
|
|
Please post the expression which you tried - the one which gives the error.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 3:26 AM
Points: 34,
Visits: 236
|
|
Below is the expression to be evaluated:
Substring (@Variable,1, (FINDSTRING( @Variable,"Full_", 1)-2))
@Variable is the variable containing the exact string 'Archive_Full_20120731200003'
But when i used this as a expression, it gives the error that substring does not allow -ve integer values.
Kindly help.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:46 AM
Points: 240,
Visits: 653
|
|
| Substring cannot take negative values for the length argument.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 3:26 AM
Points: 34,
Visits: 236
|
|
substring ("Archive_Full_20120731200002",1, (FINDSTRING( "Archive_Full_20120731200002","Full_", 1)-2))
Then how come the above expression is working where the exact string is used instead of a variable and still negative value is accepted!!! Does it make sense ?
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 4,234,
Visits: 9,470
|
|
Works for me. I suspect that you may have got your variable syntax wrong. Here is my version:
Substring (@[User::TestString],1, (FINDSTRING(@[User::TestString] ,"Full_", 1)-2))
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:46 AM
Points: 240,
Visits: 653
|
|
Devesh_Srivastava (8/1/2012) substring ("Archive_Full_20120731200002",1, (FINDSTRING( "Archive_Full_20120731200002","Full_", 1)-2))
Then how come the above expression is working where the exact string is used instead of a variable and still negative value is accepted!!! Does it make sense ?
Good question. I only know that when attempting to put in a negative value for length in a much simpler expression, it errored on negative value of length parameter.
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 4,234,
Visits: 9,470
|
|
herladygeekedness (8/2/2012)
Devesh_Srivastava (8/1/2012) substring ("Archive_Full_20120731200002",1, (FINDSTRING( "Archive_Full_20120731200002","Full_", 1)-2))
Then how come the above expression is working where the exact string is used instead of a variable and still negative value is accepted!!! Does it make sense ?Good question. I only know that when attempting to put in a negative value for length in a much simpler expression, it errored on negative value of length parameter.
The result of
FINDSTRING( "Archive_Full_20120731200002","Full_", 1) -2 is 7. That's not a negative value where I come from
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:46 AM
Points: 240,
Visits: 653
|
|
Not talking about the result, talking about the length argument.
I created a simple expression using -2 as length and was unable to save the expression due to "length cannot accept negative number" (okay, not a direct quote, but teh error was specific and when I changed length to positive number, no issues).
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Today @ 1:17 PM
Points: 4,234,
Visits: 9,470
|
|
herladygeekedness (8/2/2012) Not talking about the result, talking about the length argument.
I created a simple expression using -2 as length and was unable to save the expression due to "length cannot accept negative number" (okay, not a direct quote, but teh error was specific and when I changed length to positive number, no issues).
??
The expression I quoted was only the length argument - from the OP's example.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|