日期:2014-05-17 浏览次数:20476 次
--写的太无聊了 create table tb(name varchar(20)) insert into tb select 'ASB-34A1-P033' union select 'AB-S2-D3' union select 'ABC-S32-D34' union select 'H5-G323-FSS-G54' select REVERSE(left(REVERSE(left(RIGHT(name,len(name)-CHARINDEX('-',name)), CHARINDEX('-',RIGHT(name,len(name)-CHARINDEX('-',name)))-1)), PATINDEX('%[^0-9]%',REVERSE(left(RIGHT(name,len(name)-CHARINDEX('-',name)), CHARINDEX('-',RIGHT(name,len(name)-CHARINDEX('-',name)))-1)))-1)) from tb /* -------------------- 32 2 1 323
------解决方案--------------------
select substring(stuff(name,1,charindex('-',name),''),charindex('-',stuff(name,1,charindex('-',name),''))-1,1) from tb where len(name)-len(replace(name,'-','')) >= 2
------解决方案--------------------