how to convert id to character in series.
i want to show character according to id from sql server
like 1 to A, 2 to B, 26 to Z and 27 to AA, 28 to AB and so..on
Hi mukesh1,
Use CHAR function.
Refer below query.
SQL
CREATE TABLE #Number(Num INT) INSERT INTO #Number VALUES (1) INSERT INTO #Number VALUES (2) INSERT INTO #Number VALUES (3) INSERT INTO #Number VALUES (4) INSERT INTO #Number VALUES (5) INSERT INTO #Number VALUES (6) INSERT INTO #Number VALUES (7) INSERT INTO #Number VALUES (8) INSERT INTO #Number VALUES (9) INSERT INTO #Number VALUES (10) INSERT INTO #Number VALUES (11) INSERT INTO #Number VALUES (12) INSERT INTO #Number VALUES (13) INSERT INTO #Number VALUES (14) INSERT INTO #Number VALUES (15) INSERT INTO #Number VALUES (16) INSERT INTO #Number VALUES (17) INSERT INTO #Number VALUES (18) INSERT INTO #Number VALUES (19) INSERT INTO #Number VALUES (20) INSERT INTO #Number VALUES (21) INSERT INTO #Number VALUES (22) INSERT INTO #Number VALUES (23) INSERT INTO #Number VALUES (24) INSERT INTO #Number VALUES (25) INSERT INTO #Number VALUES (26) INSERT INTO #Number VALUES (27) INSERT INTO #Number VALUES (28) INSERT INTO #Number VALUES (53) SELECT CASE WHEN Num <= 26 THEN CHAR(64 + Num) ELSE CONCAT(CHAR(64 +(Num / 26)), CHAR(64 +(Num % 26))) END 'Letter' FROM #Number DROP TABLE #Number
Screenshot
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.