表user  字段tel010-12345678要求把-后面或前面的放到quhao字段里。。谢谢

解决方案 »

  1.   

    insert 表user(quhao)
    select left(tel,charindex('-',tel)-1)
    union all
    select substring(tel,charindex('-',tel)+1,len(tel))
      

  2.   

    同一個表應該用update
    update [user] set quhao=left(tel,charindex('-',tel)-1)
      

  3.   

    update 表user  set quhao=right(字段tel,len(字段tel)-charindex('-',字段tel)),字段tel=left(字段tel,charindex('-',字段tel)-1)
      

  4.   

    呵呵,應該是這樣:
    update [user]  set tel=right(tel,len(tel)-charindex('-',tel)),quhao=left(tel,charindex('-',tel)-1)
      

  5.   

    选出符合条件的记录后,什么都可以做select col1=left(tel,charindex('-',tel)-1),
           col2=right(tel,len(tel)-charindex('-',tel))
    from user
    where charindex('-',tel)>0
      

  6.   

    表user  字段tel010-12345678要求把-后面或前面的放到quhao字段里。。谢谢取-前面的数据:select left(tel , charindex('-',tel) -1) from user
    取-后面的数据:select substring(tel , charindex('-',tel) + 1 , len(tel)) from user
      

  7.   

    都不行服务器: 消息 536,级别 16,状态 3,行 1
    向 substring 函数传递了无效的 length 参数。
    语句已终止。
      

  8.   

    字段类型  nvarchar是不是需要修改下字段类型?
      

  9.   

    虎虎和江涛的都会报错新人类给了我启示正确的是
    update [user]  set tel=right(tel,len(tel)-charindex('-',tel)),quhao=left(tel,charindex('-',tel)-1) where charindex('-',tel)>0