Converting SQL error message to a number

  • Hi

    I am linking the results of an SQL query within MS Excel and I was wondering whether anyone knows how to convert an error message returned by SQL into a value that can be referenced in Excel.

    In the example we need to check that database table names remain constant month on month so the query is set up to check that no changes have been made to the name and outputted as something that can be measured in Excel whether it is a text or number for example. But at the moment the error message Invalid object name just appears and does not populate anything within Excel.

    Any help would be appreciated.

    Thanks

  • Emma.Thackwray (2/10/2016)


    Hi

    I am linking the results of an SQL query within MS Excel and I was wondering whether anyone knows how to convert an error message returned by SQL into a value that can be referenced in Excel.

    In the example we need to check that database table names remain constant month on month so the query is set up to check that no changes have been made to the name and outputted as something that can be measured in Excel whether it is a text or number for example. But at the moment the error message Invalid object name just appears and does not populate anything within Excel.

    Any help would be appreciated.

    Thanks

    You can use TRY CATCH to trap the error, and ERROR_NUBER() (or one of the related functions) to check the kind of error.

    https://msdn.microsoft.com/en-us/library/ms175976.aspx

    https://msdn.microsoft.com/en-US/library/ms175069.aspx


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

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

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