日期:2014-05-18  浏览次数:20411 次

字符串分割问题
有张表,里面有这样一些记录,如果找出其中的计量单位。
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

------解决方案--------------------
为什么不适应?
mg/dL-females取是要什么?mg/dL?

探讨
引用:
思路:取/前面第一个空格的位置,然后从那个位置到最后

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

这两行记录不适应

------解决方案--------------------
修正:
SQL code
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