简体   繁体   English

如何获取SQL中下面一列的数值?

[英]How to get the numeric value of the below column in SQL?

I am trying to get the value 71 out of the below sdescription column whose value is:我试图从下面的sdescription列中获取值71 ,其值为:

'€22.95 FUP BB charge for Black Waste: Total Weight: 71Kg'

Here is the code I used:这是我使用的代码:

Select
  th.sDescription,
  right(sDescription,6) as [column1]
from TransactionHistory th
join #2050FUPBB t on t.cust = th.scustomerid
where dttimestamp between '31-July 2020 00:00' and '31-Jul-2020 23:29'
and sdescription like '%€22.95 FUP BB charge for Black Waste:%'

but I only get the result: ': 71Kg'但我只得到结果: ': 71Kg'

Can you please help me get the value '71' if possible如果可能的话,你能帮我得到价值'71'

Select
  th.sDescription,
  SUBSTRING(sDescription, CHARINDEX(':', sDescription)+1, 2)
from TransactionHistory th
join #2050FUPBB t on t.cust = th.scustomerid
where dttimestamp between '31-July 2020 00:00' and '31-Jul-2020 23:29'
and sdescription like '%€22.95 FUP BB charge for Black Waste:%'

I think you want我想你想要

replace(right(txt,len(txt)-charindex('Weight:',txt)-7),'Kg','')

This should handle weight of any length这应该处理任何长度的重量

DEMO 演示

Use Replace to remove unwanted text使用替换删除不需要的文本

Select
  th.sDescription,
  Replace(Replace(right(sDescription,6),'kg',''),':','') as [column1]
from TransactionHistory th
join #2050FUPBB t on t.cust = th.scustomerid
where dttimestamp between '31-July 2020 00:00' and '31-Jul-2020 23:29'
and sdescription like '%€22.95 FUP BB charge for Black Waste:%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM