T-SQL Find char string and take all char to the right of expression

Like me

Take:

RJI#\\\\Cjserver\TrialWorks\CaseFiles\10000269\Pleadings\RJI - 10005781.doc

Find the constant expression '\\ Cjserver \' and take everything to the right of the expression, so the correct pointer would be:

\\\\Cjserver\TrialWorks\CaseFiles\10000269\Pleadings\RJI - 10005781.doc

I know some RIGHT and CHARINDEX should do this.

+4
source share
3 answers
 DECLARE @input NVarChar(1000) = 'RJI#\\Cjserver\TrialWorks\CaseFiles\10000269\Pleadings\RJI - 10005781.doc', @match NVarChar(100) = '\\Cjserver'; DECLARE @position Int = CHARINDEX(@match, @input); SELECT SUBSTRING(@input, @position, 1000); 

I just use 1000 for some arbitrarily large value. You should probably resize your data accordingly.

+3
source

You want to use a substring starting from the index after your target and occupy the entire string less than the charindex of your target.

  declare @string varchar(1000) set @string = 'xxxxxxxxyzzzzzzzz' select substring(@string, charindex('y', @string) +1, len(@string) - charindex('y', @string)) zzzzzzzz 

In this case, I want everything after y

+1
source
 DECLARE @String VARCHAR(100) SET @String = 'RJI#\\Cjserver\TrialWorks\CaseFiles\10000269\Pleadings\RJI - 10005781.doc' SELECT RIGHT(@String,LEN(@String)-PATINDEX('%\\Cjserver\%',@String)+1) 
0
source

All Articles