李先生(113806344)
张飞(272897468)
兴阳(803725)
合民(89051)
张(14053)要求显示结果:A列        B列
113806344  李先生
272897468  张飞
803725     兴阳
89051      合太
14053      张

解决方案 »

  1.   

    --------------------SQL Server数据格式化工具-------------------
    ---------------------------------------------------------------
    -- DESIGNER :happycell188(喜喜)
    --       QQ :584738179
    -- Development Tool :Microsoft Visual C++ 6.0    C Language 
    -- FUNCTION :CONVERT DATA TO T-SQL
    ---------------------------------------------------------------
    -- Microsoft SQL Server  2005
    -- Developer Edition on Microsoft Windows XP [版本 5.1.2600]
    ---------------------------------------------------------------
    ---------------------------------------------------------------use test
    go
    if object_id('test.dbo.tb') is not null drop table tb
    -- 创建数据表
    create table tb
    (
    col varchar(30)
    )
    go
    --插入测试数据
    insert into tb select '李先生(113806344)'
    union all select '张飞(272897468)'
    union all select '兴阳(803725)'
    union all select '合民(89051)'
    union all select '张(14053)'
    go
    --代码实现select A=substring(col,charindex('(',col)+1,charindex(')',col)-charindex('(',col)-1),
    B=substring(col,1,charindex('(',col)-1) from tb/*测试结果A      B
    ---------------------
    113806344 李先生
    272897468 张飞
    803725 兴阳
    89051 合民
    14053 张(5 行受影响)
    */
      

  2.   


    select Left(right(len(info)-charindex(info,'(')),Len(right(len(info)-charindex(info,'('))-1),Left(charindex(info,'(')代码没经过测试,大概思路应该是这样吧
      

  3.   

    --> 测试数据: #tmp
    if object_id('tempdb.dbo.#tmp') is not null drop table #tmp
    create table #tmp (D varchar(17))
    insert into #tmp
    select '李先生(113806344)' union all
    select '张飞(272897468)' union all
    select '兴阳(803725)' union all
    select '合民(89051)' union all
    select '张(14053)'select SubString(d,1,charindex('(',d)-1) d ,
    SubString(d,charindex('(',d)+1,len(d)-2) n from #tmpd                 n
    ----------------- -----------------
    李先生               113806344)
    张飞                272897468)
    兴阳                803725)
    合民                89051)
    张                 14053)(5 行受影响)
      

  4.   

    多了个括弧 汗--> 测试数据: #tmp
    if object_id('tempdb.dbo.#tmp') is not null drop table #tmp
    create table #tmp (D varchar(17))
    insert into #tmp
    select '李先生(113806344)' union all
    select '张飞(272897468)' union all
    select '兴阳(803725)' union all
    select '合民(89051)' union all
    select '张(14053)'select SubString(d,1,charindex('(',d)-1) d ,
    SubString(d,charindex('(',d)+1,len(d)-3) n from #tmpd                 n
    ----------------- -----------------
    李先生               113806344)
    张飞                272897468)
    兴阳                803725)
    合民                89051)
    张                 14053(5 行受影响)
      

  5.   

    select A=replace(stuff(col,1,charindex('(',col),''),')',''),
    B=left(col,charindex('(',col)-1) from tb