字符串分割问题

kaixin780 2011-09-20 01:34:55
有张表,里面有这样一些记录,如果找出其中的计量单位。
0.4-4.6 pg/mL
<125 pg/mL
<15 ??ol/L
0.8-2.0 ng/mL
5.1-14.1 ??/dL
2.0-4.4 pg/mL
0.93-1.7 ng/dL
0.27-4.2 ??U/mL
98 - 107 mmol/L
22 - 29 mmol/L
60-117 mg/dL-females
66-133 mg/dL males



找出,pg/ml,ng/ml,mg/dL and etc
...全文
78 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaixin780 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 qianjin036a 的回复:]
dL 是什么东东?
教了几十年化学,木有见过这个单位!
[/Quote]
dL=分升

不需要做distinct,如果有两个空格会有问题
-晴天 2011-09-20
  • 打赏
  • 举报
回复
dL 是什么东东?
教了几十年化学,木有见过这个单位!
-晴天 2011-09-20
  • 打赏
  • 举报
回复
修正:
create table tb(jldw nvarchar(20))
insert into tb select '0.4-4.6 pg/mL'
insert into tb select '<125 pg/mL'
insert into tb select '<15 ??ol/L'
insert into tb select '0.8-2.0 ng/mL'
insert into tb select '5.1-14.1 ??/dL'
insert into tb select '2.0-4.4 pg/mL'
insert into tb select '0.93-1.7 ng/dL'
insert into tb select '0.27-4.2 ??U/mL'
insert into tb select '98 - 107 mmol/L'
insert into tb select '22 - 29 mmol/L'
insert into tb select '60-117 mg/dL-females'
insert into tb select '66-133 mg/dL males'
go
select distinct * from(
select right(jldw,charindex(' ',REVERSE(jldw))-1)jldw from tb
)t where charindex('?',jldw)=0 and charindex('-',jldw)=0 and charindex('/',jldw)>0
/*
jldw
--------------------
mmol/L
ng/dL
ng/mL
pg/mL

(4 行受影响)
*/
go
drop table tb

-晴天 2011-09-20
  • 打赏
  • 举报
回复
create table tb(jldw nvarchar(20))
insert into tb select '0.4-4.6 pg/mL'
insert into tb select '<125 pg/mL'
insert into tb select '<15 ??ol/L'
insert into tb select '0.8-2.0 ng/mL'
insert into tb select '5.1-14.1 ??/dL'
insert into tb select '2.0-4.4 pg/mL'
insert into tb select '0.93-1.7 ng/dL'
insert into tb select '0.27-4.2 ??U/mL'
insert into tb select '98 - 107 mmol/L'
insert into tb select '22 - 29 mmol/L'
insert into tb select '60-117 mg/dL-females'
insert into tb select '66-133 mg/dL males'
go
select distinct * from(
select right(jldw,charindex(' ',REVERSE(jldw))-1)jldw from tb
)t where charindex('?',jldw)=0 and charindex('-',jldw)=0
/*
jldw
--------------------
males
mmol/L
ng/dL
ng/mL
pg/mL

(5 行受影响)

*/
go
drop table tb

kaixin780 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 geniuswjt 的回复:]
为什么不适应?
mg/dL-females取是要什么?mg/dL?


引用 6 楼 kaixin780 的回复:
引用 4 楼 geniuswjt 的回复:
思路:取/前面第一个空格的位置,然后从那个位置到最后

取/前面第一个空格的位置,然后从那个位置到最后
60-117 mg/dL-females
66-133 mg/dL males

这两行记录不适应
[/Quote]
geniuswjt 2011-09-20
  • 打赏
  • 举报
回复
为什么不适应?
mg/dL-females取是要什么?mg/dL?

[Quote=引用 6 楼 kaixin780 的回复:]
引用 4 楼 geniuswjt 的回复:
思路:取/前面第一个空格的位置,然后从那个位置到最后

取/前面第一个空格的位置,然后从那个位置到最后
60-117 mg/dL-females
66-133 mg/dL males

这两行记录不适应
[/Quote]
kaixin780 2011-09-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 geniuswjt 的回复:]
思路:取/前面第一个空格的位置,然后从那个位置到最后
[/Quote]
取/前面第一个空格的位置,然后从那个位置到最后
60-117 mg/dL-females
66-133 mg/dL males

这两行记录不适应
kaixin780 2011-09-20
  • 打赏
  • 举报
回复
因为没有对应规则,所以很麻烦,还不能用函数。
geniuswjt 2011-09-20
  • 打赏
  • 举报
回复
思路:取/前面第一个空格的位置,然后从那个位置到最后
--小F-- 2011-09-20
  • 打赏
  • 举报
回复
没有对应的规则么?
dawugui 2011-09-20
  • 打赏
  • 举报
回复
select * from tb where charindex('/',col) > 0
dawugui 2011-09-20
  • 打赏
  • 举报
回复
找出其中的计量单位?

带/都算?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧