ISINTEGER function

  • Comments posted to this topic are about the item ISINTEGER function


    What's the business problem you're trying to solve?

  • How do you take care of Maximum integer value ?

    SELECT dbo.fn_ISINTEGER ('1234567891002')

    gives 1 saying that it is valid int, but

    SELECT CONVERT(INT,'1234567891002')

    throws error

  • Since the OP doesn't actually test the bounds of an specific integer type, it can be confusing. However, the Reg-Ex in the OP is nice, and I prefer to use it directly in my WHERE clause instead of a function, such as:

    SELECT

    1

    WHERE

    MyField NOT LIKE '%[^0-9]%'

    Double-negeatives are... awesome... at least in this case.

    To break it down, the LIKE + "^" with wildcard "%" surrounding the pattern returns true if *any* character in the test string set is not in the set of 0 to 9.

    The NOT returns true only if the LIKE condition returns false.

    However, one cannot just take out both of the negatives and get the same result, as the pattern would then only search to see if any single character in the string was a valid 0 to 9 digit, regardless if other characters in the test string set were not.

    So, I SELECT 'LIKE' WHERE 'NOT' NOT LIKE '[^NOT]' (Result = 'LIKE'), and which backwards NOT is a ton spelled.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply