日期:2014-05-17  浏览次数:20327 次

sql问题,求解
各位好:


       现在一表,里面有N多个数据:如:我爱我家(1234567)、您好(4567543)、广州市(987678)等等

如何批量取出括号里的数据并显示出来。谢谢
SQL

------解决方案--------------------
这个是一列的值还是多列的值?
------解决方案--------------------

create table #(id int ,name varchar(30),add1 varchar(30))

insert into #
select  3  , '我爱我家(1234567)' ,  'xxx22' union all
select  4  , '您好(4567543)'     ,  'ereww' union all
select  5  , '广州市(987678)'     ,  'eeee' 


select *,substring(name,charindex('(',name)+1,charindex(')',name)-charindex('(',name)-1)number from #

/*
id          name                           add1                           number                         
----------- ------------------------------ ------------------------------ ------------------------------ 
3           我爱我家(1234567)                  xxx22                          1234567
4           您好(4567543)                    ereww                          4567543
5           广州市(987678)                    eeee                           987678

(3 row(s) affected)
*/

------解决方案--------------------
select substring(name,charindex('(',name)+1,charindex(')',name)-charindex('(',name)-1) as 数字 from 表A