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

怎么实现'A' + 1 = 'B'

2012-05-27 
如何实现A + 1 B现在有一个表如:idscore150250350我如何用把字母1处改为1A,2处改为2B,把3改为3C我的

如何实现'A' + 1 = 'B'
现在有一个表   如:
          id                   score
          1                         50
          2                         50
          3                         50

我如何用把字母1处改为1A,2处改为2B,把3改为3C

我的方法是

DECLARE   @temp_char   VARCHAR(10),@temp_int   int     //设置临时变量

SELECT   @temp_char   =   'A '

为什么下面这里就报错呢   说不能转换
SELECT   @temp_int   =   convert(INT,   @temp_char)
SELECT   @temp_int   =   @temp_int   +   1
SELECT   @temp_char   =   convert(VARCHAR(10),   @temp_int)


[解决办法]

SQL code
create table tb(id int,score int)insert into tbselect 1,10 union allselect 2,34goselect *,char(ascii('A')+(id-1)%26) as wordfrom tbdrop table tb/****************id          score       word----------- ----------- ----1           10          A2           34          B(2 行受影响)
[解决办法]
SQL code
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 allselect 2,50 union allselect 3,50select LTRIM([id])+CHAR(64+id) as id,[score] from test/*id    score1A    502B    503C    50*/ 

热点排行
Bad Request.