sql-server - 在多个地方提取部分字符串
问题描述
如何提取此字符串的一部分
declare @string varchar(1024)
set @string = 'Total # of bytes : 128270200832 (119.46GB)'
select Substring (@string, Charindex( ':', @string )+2 , Len(@string))
我只需要后面的数字:并且没有(119.46GB)
解决方案
使用replace()
:
select replace(replace(Substring (@string, Charindex( ':', @string )+2 , Len(@string)), '(', ''), ')', '');
编辑:如果你不想要里面的值,()
那么你可以这样做:
select left(col, charindex('(', col) - 1)
from ( values (Substring (@string, Charindex( ':', @string )+2 , Len(@string)))
) t(col);
推荐阅读
- python - 将视频列表合并为一个视频
- reporting-services - SSRS - hh:mm:ss tt 显示为“hh:mm:ss tt”而不是实际时间
- java - 如何使用带有 arraylist 对象的 IF 语句并在其上调用 size() 方法。在 Java 中
- python - 正则表达式不包括匹配组中的零宽度断言
- swift - 带有关联值的枚举 + 泛型 + 带有关联类型的协议
- python - selenium 无法在知乎提交答案
- javascript - 在 javascript 变量和 HTML 属性值中使用 BASE64 编码字符串是否安全?
- r - gplots heatmap.2 慢,Rowv=FALSE
- javascript - 固定标题和锚链接:如何减少可点击区域?
- rundeck - 通过 Ansible 管理 Rundeck