[英]Substring of a Substring
I have a text field (field named "BiographyText" in the "Employs" table) in SQL Server 2008 which stores KPI target figures: 我在SQL Server 2008中有一个文本字段(在“Employs”表中名为“BiographyText”的字段),它存储KPI目标数字:
rebfirst60,
reifirst1.3,
retfirst50
The first target is 60, for RebFirst, the second is 1.3 for ReiFirst and 50 for the third, RetFirst. 第一个目标是60,对于RebFirst,第二个目标是ReiFirst为1.3,第三个为RetFirst为50。
I want to be able to return the 3 different numerical values, as these would be deemed the targets for each kpi for a certain employee. 我希望能够返回3个不同的数值,因为这些数值将被视为某个员工每个kpi的目标。
I am having a complete mind block trying to figure out the best way to do this, any advice/help? 我有一个完整的思维模块试图找出最好的方法,任何建议/帮助?
Overall I am trying to find the kpiname ("rebfirst") and then retrieve the next 2 characters/digits 总的来说,我试图找到kpiname(“rebfirst”),然后检索接下来的2个字符/数字
I tried the following, but it errors on function 2 of the first substring, as it is non-numeric: 我尝试了以下内容,但它在第一个子字符串的函数2上出错,因为它是非数字的:
select SUBSTRING(biographytext,SUBSTRING('rebfirst',1,2),2) from employs
Thanks 谢谢
Try this 尝试这个
SELECT
CASE WHEN PatIndex('%[a-z]%',REVERSE(BiographyText)) > 0
THEN RIGHT(BiographyText,PatIndex('%[a-z]%',REVERSE(BiographyText))-1)
ELSE '' END AS target
FROM employs
and also check another solution using function 并使用函数检查另一个解决方案
From Post The first target is 60, for RebFirst, the second is 1.3 for ReiFirst and 50 for the third, RetFirst. 从邮报第一个目标是60,对于RebFirst,第二个目标是ReiFirst为1.3,第三个为RetFirst为50。
From Comment I don't need the actual kpiname from this just the value 从评论我不需要从这个值的实际kpiname
The following Query
will give you the Answer. 以下
Query
将为您提供答案。
select case column_name when 'rebfirst60' then 60
when 'reifirst1.3' then 1.3
when 'retfirst50' then 50
from employs
I have this now by using the following: 我现在使用以下内容:
select
SUBSTRING(SUBSTRING(biographytext,1,10),9,2) as RebookingFirst,
SUBSTRING(SUBSTRING(biographytext,11,20),12,3) as ReInventFirst,
SUBSTRING(SUBSTRING(biographytext,21,30),16,3) as ReCreateFirst,
SUBSTRING(SUBSTRING(biographytext,31,40),20,2) as RetentionFirst,
SUBSTRING(SUBSTRING(biographytext,41,50),23,2) as ReferralsFirst
from employs
This gives me the results for each kpi 这给了我每个kpi的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.