Using TSQL, can I increment a CHAR(1) column by one and use it in a LEFT OUTER JOIN without a CASE statement?

后端 未结 2 643
独厮守ぢ
独厮守ぢ 2021-01-18 10:19

This question is similar to my last question. Except this time I\'m using letters rather than 6 digit integers. I want to find the out of sequence \"letters\".

Let\

相关标签:
2条回答
  • 2021-01-18 10:33

    You can convert the char(1) to its ascii number using

    ASCII(Letter)
    

    You can then increment this by one and return it to a letter using CHAR (if necessary), so your code would be this:

    SELECT * from TABLE1 t1 
    LEFT OUTER JOIN TABLE2 t2 
          ON ASCII(t1.INTCol) - 1 = ASCII(t2.INTCol) 
          AND t1.date = t2.date
    WHERE t2.id IS NULL
    
    0 讨论(0)
  • 2021-01-18 10:37

    You can use the ASCII() function to convert a character to its ASCII value:

    ASCII(Letter)

    0 讨论(0)
提交回复
热议问题