日期:2014-05-17 浏览次数:20616 次
create table table_1(ID int, GYLX varchar(100))
insert into table_1
select 1 ,'3j-4b-5x' union all
select 2 ,'4b-3j-7zp' union all
select 3 ,'12zp' union all
select 4 ,'0g' union all
select 5 ,''
go
select ID,GYLX
from
(
select *,
ROW_NUMBER() over(partition by case when GYLX like '%0%' then 0
when GYLX like '%7%' then 7
end order by id desc) rownum
from table_1
where GYLX like '%0%' or GYLX like '%7%'
)t
where rownum = 1
/*
ID GYLX
4 0g
2 4b-3j-7zp
*/
--create function [dbo].[m_getnumberV2.0]
--(
-- @mysql_one nvarchar(200)
--)
--returns varchar(200)
--begin
-- declare @mysql_two varchar(200)
-- declare @sql_one int
-- declare @sql_two int
-- select @sql_one= patindex('%[0-9.]%',@mysql_one)
-- select @sql_two=
-- patindex('%[^0-9.]%',
-- substring(@mysql_one,patindex('%[0-9.]%',@mysql_one),len(@mysql_one)-patindex('%[0-9.]%',@mysql_one)+1))
-- &nbs