sql 数据库问题 谢谢

来源:百度知道 编辑:UC知道 时间:2024/09/25 00:31:46
l_student表中的数据
是(c_school = '110509') AND (c_year = 2004) 范围内的

c_code
41105090001
41105090002
41105090003
41105090004
41105090005
41105090006
41105090007
41105090008
41105090009
41105090010
41105090011
41105090012
41105090013
41105090014
我想吧前两位41更改为62怎么更改啊 用什么命令 谢谢
请问完整的命令是多少啊 谢谢

UPDATE 表名
SET 字段名 = replace (字段名,'a','zzzzz')
打把字段名里有'a'的替换'zzzzz'了.

UPDATE l_student
set c_code = replace (c_code ,'41','62')

replace不好,很可能其它位置也包含41,可以使用stuff函数
update l_student
set c_code=stuff(c_code,1,2,'62')
where (c_school = '110509') AND (c_year = 2004) and c_code like '41%'

更新之前最好用select查看结果是否有误
select c_code,stuff(c_code,1,2,'62')
from l_student where (c_school = '110509') AND (c_year = 2004) and c_code like '41%'