SQL Server 2008 - order by strings with number numerically

前端 未结 5 1432
感动是毒
感动是毒 2020-12-01 16:06

I have following values in my table:

ABC
ABC1
ABC2
ABC3 and so on...

ABC11
ABC12
ABC13 and so on..

ABC20
ABC21
ABC22 and so on..

So basic

5条回答
  •  攒了一身酷
    2020-12-01 17:03

    (based on answers from @shenhengbin and @EchO to this question)

    The following is what I call a "clean hack". Assuming you are ordering on column Col1:

    ORDER BY LEN(Col1), Col1
    

    It is a hack, although I'd personally feel proud using it.

提交回复
热议问题