1. 程式人生 > >步步為營-104-SQL語句(截取字符串)

步步為營-104-SQL語句(截取字符串)

業務 roc sub temp string 語句 from bsp 新增

按照指定字符截取字符串,截取出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語句(截取字符串)