how to filter just numbers from varchar value?

  • when i try to execute the below query it throws an error "Conversion failed when converting the varchar value '1131-' to

    data type int."

    SELECT dbo.fn_int_only('11AB31-A')

    but SELECT dbo.fn_int_only('11AB31') this query returns a proper result like 1131

    is there any other ways to filter only INT values? or how do i overcome this error?

  • deepthipayal01 (7/27/2013)


    when i try to execute the below query it throws an error "Conversion failed when converting the varchar value '1131-' to

    data type int."

    SELECT dbo.fn_int_only('11AB31-A')

    but SELECT dbo.fn_int_only('11AB31') this query returns a proper result like 1131

    is there any other ways to filter only INT values? or how do i overcome this error?

    Step 1 would be to post the code for the user defined function that you're using.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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