T1
名称 规格
A 1.1g
b 2ml:2XX
c 0.9q*dd
结果
名称 规格
A 1.1
b 2
c 0.9
取规格最左边的第一组数值。谢谢
------解决方案--------------------
with tb(a,b) as (
select 'A', '1.1g' union all
select 'b', '2ml:2XX' union all
select'c', '0.9q*dd'
)
select a 名称,left(b,PATINDEX('%[^(0.0-9]%',b)-1)规格 from tb
这个好像不支持负数...

------解决方案--------------------
这个我有个笨方法,你试试下面的语句吧...
select replace(replace(replace(convert(varchar,getdate(),20),'-',''),' ',''),':','')
--把getdate()换了即可
------解决方案--------------------
select a 名称,left(b,PATINDEX('%[a-zA-Z]%',b)-1)规格 from tb
------解决方案--------------------
SELECT [名称],LEFT([规格],PATINDEX('%[^0-9.]%',[规格])-1) AS [规格] FROM T1
------解决方案--------------------
if OBJECT_ID('T1','U') is not null
drop table T1
go
create table T1
(
名称 nvarchar(20),
规格 nvarchar(20)
)
go
insert into T1 values
('A','1.1g'),
('b','2ml:2XX'),
('c','0.9q*dd')
--SQL
select 名称, left(规格,patindex('%[^0-9.]%',规格)-1) 规格 From T1
--结果集
/*
名称 规格
A 1.1
b 2
c 0.9
*/