Expected error not raised

  • Hi Guys!Pl help me if you can!I'm having a table in which a column is having int datatype. When non-int (char) data is being inserted, it is terminating the application although error handling is there in sp. When I analysed, I found control is not at all transferred to the error handling.Thanks in adv.Ashesh


    Thanks,
    Ashesh

  • You must catch an error in the very next statement after attemting insert.

    _____________
    Code for TallyGenerator

  • You cannot trap this error in sp only the application, SQL Server will not execute any statement following this type of error.

    The only exception may be SQL 2005 with TRY...CATCH

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Since the error is caused by the attempt to convert a column's data type, simply add a WHERE clause that will exclude all rows where this column's data cannot be converted.

    An alternative to the WHERE is to use:

    IntField = CASE WHEN IntInChar LIKE '[0-9]' THEN IntInChar ELSE NULL END

    To NULL that column value for the rows that cannot be converted to int.

    Just depends on what you want done with the "bad" data.

    Andy

  • Nice one Andy

    After I posted I thought of posting similar but didn't

    If the input is greater than one char then use the following

    LIKE '[0-9-]' + REPLICATE('[0-9]',LEN([column])-1)

     

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hi All!

    Thanks a lot for the response. This is really a nice turn around for capturing the error. I think this will help me a lot.

    Thanks again

    Ashesh


    Thanks,
    Ashesh

Viewing 6 posts - 1 through 5 (of 5 total)

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