ORDER/SORT Column mixed number and number prefixed by char

前端 未结 4 1654
野的像风
野的像风 2021-01-18 12:42

I have a varchar column conteining a code, this code could by only numbers, or number prefixed by a char for example i have a column containing this data :

         


        
4条回答
  •  攒了一身酷
    2021-01-18 13:22

     CASE
        WHEN ISNUMERIC(Col) = 1 THEN '@'
        Else LEFT(Col, 1)
     END
    ,CASE
        WHEN ISNUMERIC(Col) = 1 THEN Convert(int, Col)
        Else Convert(int, RIGHT(Col, LEN(Col) - 1))
     END
    

提交回复
热议问题