Select max int from varchar column

前端 未结 9 1219
离开以前
离开以前 2021-02-19 04:07

I am trying to retrieve the largest number from a varchar column that includes both numbers and strings. An example of the data I\'m working with:

BoxNumber

9条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 04:40

    Why not

    SELECT MAX(CAST(Value AS Int)) FROM #bla 
    WHERE ISNUMERIC(Value)=1 
        AND Value LIKE '%[0-9]%' 
    

    then you're only dealing with numeric strings. In this case you may not need ISNUMERIC()

提交回复
热议问题