[英]Extract Number from String Field Including Decimal SQL Server 18
我想从 SQL 中包含十进制的字符串字段中提取数字。
我当前的代码
substring(a.LastTitrate,patindex('%[0-9]%', a.LastTitrate),patindex('%[0-9][^0-9]%', a.LastTitrate)-patindex('%[0-9]%', a.LastTitrateCumulativeVolume)+1) as mL
我目前的结果
0.542 mls 0
0.042 mls 0
0.317 mls 0
期望的结果
0.542 mls 0.542
0.042 mls 0.042
0.317 mls 0.317
带有 patindex 的 left 就可以了。
select LastTitrate
, left(LastTitrate, patindex('%[0-9] ml%', LastTitrate)) as mL
from your_table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.