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

前端 未结 3 1055
野性不改
野性不改 2021-01-19 10:56

How do I

Take:

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

Find Constant expression \'\\\\Cjse

相关标签:
3条回答
  • 2021-01-19 11:33
    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'm just using 1000 for some arbitrarily large value. You should probably size this more appropriately to your data.

    0 讨论(0)
  • 2021-01-19 11:44

    You want to use Substring, starting one after the index of your target, and take the length of the entire string less 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 the y

    0 讨论(0)
  • 2021-01-19 11:45
    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 讨论(0)
提交回复
热议问题