1-A
2-B
3-C
Etc etc
请帮我写一下这个功能。
答案 0 :(得分:0)
尝试此逻辑
DECLARE @MyNum INT = 1
SELECT
CharVal = CHAR(64+@MyNum),
InputNum = @MyNum
如果要生成完整的列表
,请尝试此操作DECLARE @Start INT = 1
;WITH CTE
AS
(
SELECT
CharVal = CHAR(64+@Start),
SeqNo = @Start
UNION ALL
SELECT
CharVal = CHAR(64+SeqNo+1),
SeqNo = SeqNo+1
FROM CTE
WHERE CHAR(64+SeqNo+1) <> 'Z'
)
SELECT
*
FROM CTE
将@Start中的值设置为您希望开始的位置
答案 1 :(得分:0)
DECLARE @alpha VARCHAR(MAX)
SET @alpha = 'M'
select CASE WHEN CAST(CAST(@alpha as VARBINARY) AS INT) >= 64 THEN CAST(CAST(@alpha as VARBINARY) AS INT) - 64 END
试试这个,只需将Alphabet转换为整数。您可以循环运行它并获得所需的输出。
答案 2 :(得分:0)
在Postgres中你可以做到:
select nr, chr(nr + 64)
from generate_series(1,26) as t(nr)
order by nr;