首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个SQL批量执行语句大家帮帮忙。解决方案

2012-02-27 
一个SQL批量执行语句大家帮帮忙。。表user字段tel010-12345678要求把-后面或前面的放到quhao字段里。。谢谢[解

一个SQL批量执行语句大家帮帮忙。。
表user     字段tel

010-12345678

要求

把-后面或前面的放到quhao字段里。。谢谢

[解决办法]
update 表user set quhao=right(字段tel,len(字段tel)-charindex( '- ',字段tel)),字段tel=left(字段tel,charindex( '- ',字段tel)-1)
[解决办法]
呵呵,應該是這樣:
update [user] set tel=right(tel,len(tel)-charindex( '- ',tel)),quhao=left(tel,charindex( '- ',tel)-1)
[解决办法]
选出符合条件的记录后,什么都可以做

select col1=left(tel,charindex( '- ',tel)-1),
col2=right(tel,len(tel)-charindex( '- ',tel))
from user
where charindex( '- ',tel)> 0
[解决办法]
表user 字段tel

010-12345678

要求

把-后面或前面的放到quhao字段里。。谢谢

取-前面的数据:select left(tel , charindex( '- ',tel) -1) from user
取-后面的数据:select substring(tel , charindex( '- ',tel) + 1 , len(tel)) from user

热点排行