-->创建表 if object_id('tb') is not null drop table tb goCREATE TABLE tb(NAME VARCHAR(20)) insert tb select 'A' insert tb select 'B' insert tb select 'C' select char(ascii(name)+1) name from tb /* name ---- B C D(3 行受影响) */
加一个判断应该可以的吧 有没有更好的办法呢?期待ing~~
应该考虑下Z,Z转换为A的话select name =case when name<>'Z' then char(ascii(name)+1) else 'A' from tb
应该考虑下Z,Z转换为A的话 select name =case when name <>'Z' then char(ascii(name)+1) else 'A' end from tb
declare @i int,@t varchar(20) set @t='Z' select @i=ascii(@t) if(@i>89) set @i=64 set @i=@i+1 select char(@i)/*
---- A(所影响的行数为 1 行)*/
原來還有ascii這個函數可以使用 呵呵 學習了結貼給分
update tb set col=char(ascii('A')+1) where col='A' update tb set col='B' where col='A'
/*
----
B(1 行受影响)
*/
select char(ascii('A')+1)
到了Z,就不能这样了
if object_id('tb') is not null
drop table tb
goCREATE TABLE tb(NAME VARCHAR(20))
insert tb select 'A'
insert tb select 'B'
insert tb select 'C'
select char(ascii(name)+1) name from tb
/*
name
----
B
C
D(3 行受影响)
*/
有没有更好的办法呢?期待ing~~
from tb
from tb
set @t='Z'
select @i=ascii(@t)
if(@i>89) set @i=64
set @i=@i+1
select char(@i)/*
----
A(所影响的行数为 1 行)*/
呵呵
學習了結貼給分