Wednesday, March 7, 2012

Displaying Char from an integer field

I have a field, SortOrder, that is an integer field that will be (0,1,2,3,4,
etc).
I want to display it as (A,B,C,D,E, etc)
Using something like:
select SortOrder from skillsAnswers
Is there a way to make 0 an "A", 1 a "B", etc in a select statement?
Thanks,
Tom.If the numbers are limited, you can use CASE. Alternatively you can add the
ASCII values if these are strictly alphabets.
Perhaps, you can explain what requires you to attempt something like this
and someone here might offer a better suggestion.
Anith|||"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:%23rf68NlAFHA.1564@.TK2MSFTNGP09.phx.gbl...
> If the numbers are limited, you can use CASE. Alternatively you can add
> the ASCII values if these are strictly alphabets.
> Perhaps, you can explain what requires you to attempt something like this
> and someone here might offer a better suggestion.
What I am doing is setting up some Question and Answers scenarios in which I
could be changing the order of the display. The order is going to
determined by the field SortOrder. As I add a new answer, the SortOrder is
incremented by 1. The order can be changed later by just changing the
values of these fields (but they always will be in order sequentually
0,1,2... with not missing numbers).
I want to display the answers the way you normally display questions and
answers as "A,B,C..."
Thanks,
Tom
> --
> Anith
>|||>> The order can be changed later by just changing the values of these
Perhaps I may be missing the big picture here, but why not use a CHAR(1)
column instead of an INTEGER?
Anith|||"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:ORtCvXlAFHA.2640@.TK2MSFTNGP14.phx.gbl...
> Perhaps I may be missing the big picture here, but why not use a CHAR(1)
> column instead of an INTEGER?
It would be a 6 of one type of solution. I am using the SortOrder as the
index into a bit pattern. I am setting bits in a work to tell me what the
person picked (0 will set the first bit, 1 the 2nd etc).
I did end up doing sort of what you suggested, which works fine,
SELECT SortOrder=char(Sortorder+65),Answer,
Thanks,
Tom.
> --
> Anith
>

No comments:

Post a Comment