Given Letter, Get Next Letter in Alphabet

后端 未结 5 537
天涯浪人
天涯浪人 2021-01-17 19:18

I have letter \"a\", \"b\", \"c\". I would like my results to be \"b\", \"c\", \"d\" in TSQL respectively. Would what I use to achieve this?

5条回答
  •  旧时难觅i
    2021-01-17 19:47

    DECLARE @Letters AS TABLE
    (
        Letter CHAR(1)
    )
    INSERT INTO @Letters
            ( Letter )
    VALUES  ( 'A' )
    INSERT INTO @Letters
            ( Letter )
    VALUES  ( 'B' )
    INSERT INTO @Letters
            ( Letter )
    VALUES  ( 'C' )
    SELECT CHAR(ASCII(Letter) + 1) FROM @Letters
    

    Example using a table variable in SQL but any of the above will do it for you. Dependant on what method your using to collate the list of letters obviously.

提交回复
热议问题