--如果列是字符型的 update tablename set colname='A'+colname --如果列是int型的,存不进去A,需要改成varchar或是nvarchar
colname这个值怎么得来的呢
declare @t table (id varchar(10)) insert into @t select 1 union all select 2 union all select 3 union all select 4 union all select 5update @t set id='A'+id select * from @t /* id ---------- A1 A2 A3 A4 A5 */
如果xlh字段是char nchar varchar nvarchar类型的 update 表c set xlh='A'+xlh 即可。
--创建一个表 create table 表c(xlh varchar(10)) insert into 表c select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 1000--查看表中数据 select * from 表c /* xlh ---------- 1 2 3 4 5 1000 */ --添加一个列 alter table 表c add nid varchar(20)--更新数据 update 表c set nid='A'+xlh--查看更新后的结果 select nid from 表c /* nid -------------------- A1 A2 A3 A4 A5 A1000 */
楼主问你怎么解决。回答跟没回答一样 搞笑!update t_menu t set t.moduleid=concat('A',t.moduleid) 如果需要加上条件的话 update t_menu t set t.moduleid=concat('A',t.moduleid) where length(t.moduleid)=1;
update tablename set colname='A'+colname
--如果列是int型的,存不进去A,需要改成varchar或是nvarchar
colname这个值怎么得来的呢
declare @t table (id varchar(10))
insert into @t
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5update @t set id='A'+id
select * from @t
/*
id
----------
A1
A2
A3
A4
A5
*/
表cxlh100
101
102
103
.
.
.
1000000改后
A100
A101
A102
A103
.
.
.
A10000
update 表c set xlh='A'+xlh 即可。
--创建一个表
create table 表c(xlh varchar(10))
insert into 表c
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 1000--查看表中数据
select * from 表c
/*
xlh
----------
1
2
3
4
5
1000
*/
--添加一个列
alter table 表c add nid varchar(20)--更新数据
update 表c set nid='A'+xlh--查看更新后的结果
select nid from 表c
/*
nid
--------------------
A1
A2
A3
A4
A5
A1000
*/
楼主问你怎么解决。回答跟没回答一样 搞笑!update t_menu t set t.moduleid=concat('A',t.moduleid)
如果需要加上条件的话
update t_menu t set t.moduleid=concat('A',t.moduleid) where length(t.moduleid)=1;