How to remove string from variable value?

  • Hi,

    I created a variable with name 'source_file' with string data type and default value is 'C:\test'. In my expression i want only 'test'.How to extract only "test" into my expression.

  • Hi

    My solution is based on the assumption that you have only a single "\" in your string. i.e. the variable will not contain a value like 'C\test\test". Note the two "\" values (slash) in the string.

    declare @e varchar(10)

    set @e = 'C:\test'

    select substring(@e,charindex('\',@e)+1,len(@e))

    Edit: - I hope you are not looking for SSIS expressions.

    "Keep Trying"

  • elchuru (5/3/2010)


    Hi,

    I created a variable with name 'source_file' with string data type and default value is 'C:\test'. In my expression i want only 'test'.How to extract only "test" into my expression.

    Check this expression:

    Replace the Variable - VariableName with your variable name in the expression

    SUBSTRING(VariableName,FINDSTRING(VariableName,"\\",1)+1,(LEN(VariableName) - FINDSTRING(VariableName,"\\",1)))

  • ChiragNS (5/3/2010)


    Hi

    My solution is based on the assumption that you have only a single "\" in your string. i.e. the variable will not contain a value like 'C\test\test". Note the two "\" values (slash) in the string.

    declare @e varchar(10)

    set @e = 'C:\test'

    select substring(@e,charindex('\',@e)+1,len(@e))

    Edit: - I hope you are not looking for SSIS expressions.

    Its SSIS expression

Viewing 4 posts - 1 through 3 (of 3 total)

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