Tsql(sql server 2005+) Set Based Approach to convert a number to letters
Sometime back I wrote a program in C# that will accept a number and will give the corresponding letter.

E.g.  
   

       Input: 1 Output: A
       Input: 45 Output: AS
       Input: 569 Output: UW
       Input: 2000 Output: BXX

The function is as under

    public static string NumberToLetters(int inputNumber)
    {
                int dividend = inputNumber;
                string letters = String.Empty;
                int modulo;
    
                while (dividend > 0)
                {
                    modulo = (dividend - 1) % 26;
                    letters = Convert.ToChar(65 + modulo).ToString() + letters;
                    dividend = (int)((dividend - modulo) / 26);
                }
                return letters;
    }

Now I have to write the same thing in SQL Server 2005. Since I am not so comfortable in SQL Server , henceforth I am looking for help.

How to do the same using **Set based approach**?

I do tried with [select char(64+1)][1]  but for input 45 or 569 or 2000 it is giving unexpected result

Thanks in advance


  [1]: http://stackoverflow.com/questions/1432722/tsql-get-letter-representation-for-a-number
Tsql(sql server 2005+) Set Based Approach to convert a number to letters
===

Sometime back I wrote a program in C# that will accept a number and will give the corresponding letter.

E.g.  
   

       Input: 1 Output: A
       Input: 45 Output: AS
       Input: 569 Output: UW
       Input: 2000 Output: BXX

The function is as under

    public static string NumberToLetters(int inputNumber)
    {
                int dividend = inputNumber;
                string letters = String.Empty;
                int modulo;
    
                while (dividend > 0)
                {
                    modulo = (dividend - 1) % 26;
                    letters = Convert.ToChar(65 + modulo).ToString() + letters;
                    dividend = (int)((dividend - modulo) / 26);
                }
                return letters;
    }

Now I have to write the same thing in SQL Server 2005. Since I am not so comfortable in SQL Server , henceforth I am looking for help.

How to do the same using **Set based approach**?

I do tried with [select char(64+1)][1]  but for input 45 or 569 or 2000 it is giving unexpected result

Thanks in advance


  [1]: http://stackoverflow.com/questions/1432722/tsql-get-letter-representation-for-a-number