开发者

a, b, c instead of serial number 1, 2, 3 in sql server

I have a SQL Server Table like below:

   S.No            ID          Name
  -------        -----        -------
    1              100       开发者_运维问答  Yuvraj
    2              101         Brian
    3              102         Paul
    4              103         Andrew
    5              104         Wasim
    6              105         Zaheer
    7              106         Shaun
    8              107         Lance

Instead of the S.No 1,2,3,4,5,6 and so on I want English Alphabets such as S.No a,b,c,d,e,f,g,h,i and so on... How to achieve this?


  • Use a normal tinyint column with a CHECK constraint to keep it between 1 and 26.
  • Add computed column with CHAR(96 + tinyint value)

The same can be done with ROW_NUMBER() to ensure contiguous numbers in a SELECT, for example.

And modulo (% 26) might come in useful at some point too

However, if you have no more than 26 values in your table why not just do it manually...


SELECT CHAR(97 + s_no) 'as_char' ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜