日期:2014-05-17 浏览次数:20564 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (name nvarchar(40))
insert into [TB]
select '中国人(4444444)' union all
select '传感器(广州)有限公司(4487778)'
select * from [TB]
SELECT name,REVERSE(SUBSTRING(REVERSE(name),2,PATINDEX('%(%',REVERSE(NAME))-2)) AS nameID
FROM dbo.TB
/*
name nameID
中国人(4444444) 4444444
传感器(广州)有限公司(4487778) 4487778*/
--更新
--UPDATE dbo.TB
--SET nameid = REVERSE(SUBSTRING(REVERSE(name),2,PATINDEX('%(%',REVERSE(NAME))-2))
SUBSTRING(name,PATINDEX('%[0-9]%',name),7)