T-SQL IsNumeric() and Linq-to-SQL

前端 未结 4 1922
再見小時候
再見小時候 2021-01-12 09:49

I need to find the highest value from the database that satisfies a certain formatting convention. Specifically, I would like to find the highest value that looks like

4条回答
  •  死守一世寂寞
    2021-01-12 10:51

    Although ISNUMERIC is missing, you could always try the nearly equivalent NOT LIKE '%[^0-9]%, i.e., there is no non-digit in the string, or alternatively, the string is empty or consists only of digits:

    from x in table 
    where SqlMethods.Like(x.col, 'EU[0-9]%') // starts with EU and at least one digit
      && !SqlMethods.Like(x.col, '__%[^0-9]%') // and no non-digits
    select x;
    

    Of course, if you know that the number of digits is fixed, this can be simplified to

    from x in table 
    where SqlMethods.Like(x.col, 'EU[0-9][0-9][0-9][0-9][0-9][0-9]')
    select x;
    

提交回复
热议问题