T-SQL 查找字符字符串并将所有字符移到表达式的右侧 [英] T-SQL Find char string and take all char to right of expression

查看:31
本文介绍了T-SQL 查找字符字符串并将所有字符移到表达式的右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么办

采取:

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

找到常量表达式 '\\Cjserver\' 并将所有内容放在表达式的右侧,因此正确的指针是:

Find 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

我知道RIGHTCHARINDEX 的某种组合应该可以做到这一点.

I know some kind of combinaton of RIGHT and CHARINDEX should do it.

推荐答案

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);

我只是将 1000 用于某个任意大的值.您可能应该根据您的数据调整其大小.

I'm just using 1000 for some arbitrarily large value. You should probably size this more appropriately to your data.

这篇关于T-SQL 查找字符字符串并将所有字符移到表达式的右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆