34,590
社区成员
发帖
与我相关
我的任务
分享
select ascii('A')
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([id] int,[score] int)
insert [test]
select 1,50 union all
select 2,50 union all
select 3,50
select LTRIM([id])+CHAR(64+id) as id,[score] from test
/*
id score
1A 50
2B 50
3C 50
*/
create table tb(id int,score int)
insert into tb
select 1,10 union all
select 2,34
go
select *,char(ascii('A')+(id-1)%26) as word
from tb
drop table tb
/****************
id score word
----------- ----------- ----
1 10 A
2 34 B
(2 行受影响)
--SQL SERVER 里面是没有问题的
--ltrim是去掉左空格,这里是将int 隐式转换成 varchar
declare @T table([id] int,[score] int)
insert @T
select 1,50 union all
select 2,50 union all
select 3,50
select ltrim(id)+char(id+64) as id,[score] from @T
/*
id score
------------- -----------
1A 50
2B 50
3C 50
*/