简体   繁体   English

T-SQL查找char字符串并将所有char设置为表达式右侧

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

How do I 我如何能

Take: 采取:

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

Find Constant expression '\\\\Cjserver\\' and take everything to the right of the expression so the correct pointer would be: 查找常量表达式'\\\\ Cjserver \\'并将所有内容放在表达式的右侧,以便正确的指针为:

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

I know some kind of combinaton of RIGHT and CHARINDEX should do it. 我知道RIGHTCHARINDEX某种组合应该这样做。

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. 我只是使用1000来获得一些任意大的价值。 You should probably size this more appropriately to your data. 您可能应该更适合您的数据。

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 你想使用Substring,在你的目标索引之后开始,并取整个字符串的长度减去目标的charindex

  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 在这种情况下,我希望在y之后的一切

DECLARE @String VARCHAR(100)
SET @String = 'RJI#\\Cjserver\TrialWorks\CaseFiles\10000269\Pleadings\RJI - 10005781.doc'

SELECT RIGHT(@String,LEN(@String)-PATINDEX('%\\Cjserver\%',@String)+1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM