从entity_index 这张表的dwgmc这一列中提取图中画出椭圆形的一连串数字(档号)如果没有档号的可以忽略。求高手帮忙急用!!!

解决方案 »

  1.   


    declare @t table (dwgmc varchar(48))
    insert into @t
    select '011-钢梯T6-091(0600-8022-501)[td-tl]{asdfsdf}' union all
    select '011-钢梯T6-091(0600-8022-505)[td-tl213]{asdfsdf}' union all
    select '011-钢梯T6-091[td-tl1231]{asdfsdf}' union all
    select '011-钢梯T6-091(0600-8022-501)[td-tl123]{asdfsdf}'select 
    case when charindex('(',dwgmc)>0 and
    charindex(')',dwgmc)>0
    then 
    substring(dwgmc,charindex('(',dwgmc)+1,charindex(')',dwgmc)-charindex('(',dwgmc)-1)
    else '无' end as dwgmc
    from @t
    /*
    dwgmc
    ------------------------------------------------
    0600-8022-501
    0600-8022-505

    0600-8022-501
    */
      

  2.   


    执行的时候报这个错误,请问什么原因呐?
    消息 536,级别 16,状态 5,第 1 行
    传递到 SUBSTRING 函数的长度参数无效。
      

  3.   


    我就是执行了select case when charindex('(',dwgmc)>0 and charindex(')',dwgmc)>0     then substring(dwgmc,charindex('(',dwgmc)+1,charindex(')',dwgmc)-charindex('(',dwgmc)-1) else '无' end as dwgmc from entity_index 这句话报的错误!该怎么改?
      

  4.   


    select 
    case when charindex('(',dwgmc)>0 and charindex(')',dwgmc)>0 and charindex('(',dwgmc)<charindex(')',dwgmc)
    then 
    substring(dwgmc,charindex('(',dwgmc)+1,charindex(')',dwgmc)-charindex('(',dwgmc)-1) 
    else '无' end as dwgmc 
    from entity_index你再试一试... 这个和数据有关系,应该是有部分特殊数据,但是我现在看不到特殊性。
      

  5.   


    sorry,老大,我看错了在类似(0600-8022-501) 之前有些列还有其他的[color=#FF0000](这个中文状态下输入的括号,怎么也一起去掉???[/color]
      

  6.   


    create table tb20111110(dwgmc varchar(60))
    insert into tb20111110
    select '(aa)011-钢梯T6-091(0600-8022-501)[td-tl]{asdfsdf}' union all
    select '011-钢梯T6-091(0600-8022-505)[td-tl213]{asdfsdf}' union all
    select '011-钢梯T6-091[td-tl1231]{asdfsdf}' union all
    select '011-钢梯T6-091(0600-8022-501)[td-tl123]{asdfsdf}'select 
        case when charindex('(',dwgmc)>0 and
        charindex(')',dwgmc)>0
        then 
        substring(dwgmc,charindex('(',dwgmc)+1,charindex(')',dwgmc)-charindex('(',dwgmc)-1)
        else '无' end as dwgmc
    from tb20111110
    /*
    dwgmc
    ------------------------------------------------------------
    aa
    0600-8022-505

    0600-8022-501(4 行受影响)
    */
    alter table tb20111110 alter column dwgmc nvarchar(60) collate chinese_prc_ci_as_ws   select 
        case when charindex('(',dwgmc)>0 and
        charindex(')',dwgmc)>0
        then 
        substring(dwgmc,charindex('(',dwgmc)+1,charindex(')',dwgmc)-charindex('(',dwgmc)-1)
        else '无' end as dwgmc
    from tb20111110 /*
    dwgmc
    ------------------------------------------------------------
    0600-8022-501
    0600-8022-505

    0600-8022-501(4 行受影响)
    */
    让它区分宽度就可以了。
      

  7.   


    老大我又发了一个帖子http://bbs.csdn.net/topics/390276599