首页 > 数据库技术 > 详细

步步为营-104-SQL语句(截取字符串)

时间:2018-07-10 19:40:00      阅读:194      评论:0      收藏:0      [点我收藏+]

按照指定字符截取字符串,截取出300

技术分享图片

 

 业务需求:想比对图片中框线部分是否一致

技术分享图片

第一步 从最后一个/截取到末尾

select top 1 reverse(substring(reverse(ProcessControlName),1,charindex(‘/‘,reverse(ProcessControlName)) - 1)) from ProcessPublish;

技术分享图片

--第二步 在第一步的基础上从最后一个.截取
select RTRIM(LTRIM(reverse(substring(reverse(ProcessControlName),1,charindex(‘/‘,reverse(ProcessControlName)) - 1)))) as web端模板,RTRIM(LTRIM(reverse(substring(reverse(MobileFormTemplatePath),1,charindex(‘/‘,reverse(MobileFormTemplatePath)) - 1)))) as 手机端模板, *
from ProcessPublish
where ProcessID >2489 --新增加的"华济建设"
and ProcessControlName != ‘‘ --模板不等于空,说明bpm发起的
and MobileFormTemplatePath != ‘‘

 技术分享图片

--第三步 在第二步的基础上获取去掉.html字段
select top 1 (substring((substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName)))),1,charindex(‘/‘,(substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName))))) - 1)) from ProcessPublish

技术分享图片

最后,完成

select (substring((substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName)))),1,charindex(‘/‘,(substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName))))) - 1)) as web端模板,
(substring((substring(reverse(MobileFormTemplatePath),charindex(‘.‘,reverse(MobileFormTemplatePath))+1,len(reverse(MobileFormTemplatePath))-charindex(‘.‘,reverse(MobileFormTemplatePath)))),1,charindex(‘/‘,(substring(reverse(MobileFormTemplatePath),charindex(‘.‘,reverse(MobileFormTemplatePath))+1,len(reverse(MobileFormTemplatePath))-charindex(‘.‘,reverse(MobileFormTemplatePath))))) - 1)) as 手机端模板, *
from ProcessPublish
where ProcessID >2489 --新增加的"华济建设"
and ProcessControlName != ‘‘ --模板不等于空,说明bpm发起的
and MobileFormTemplatePath != ‘‘
and (substring((substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName)))),1,charindex(‘/‘,(substring(reverse(ProcessControlName),charindex(‘.‘,reverse(ProcessControlName))+1,len(reverse(ProcessControlName))-charindex(‘.‘,reverse(ProcessControlName))))) - 1)) != (substring((substring(reverse(MobileFormTemplatePath),charindex(‘.‘,reverse(MobileFormTemplatePath))+1,len(reverse(MobileFormTemplatePath))-charindex(‘.‘,reverse(MobileFormTemplatePath)))),1,charindex(‘/‘,(substring(reverse(MobileFormTemplatePath),charindex(‘.‘,reverse(MobileFormTemplatePath))+1,len(reverse(MobileFormTemplatePath))-charindex(‘.‘,reverse(MobileFormTemplatePath))))) - 1))

技术分享图片

查出来有三处不一致

步步为营-104-SQL语句(截取字符串)

原文:https://www.cnblogs.com/YK2012/p/9291031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!