• eugene.pipko (10/29/2012)


    What about any other error? There is no front end. The result is emailed to the user.

    I guess what I am trying to do is to let the other 2 parts of the union all work and report 'no_data',0 for the part that failed.

    Is it possible is SS 2K8R2?

    The front end doesn't have to be visual. Something gets the results and emails it. Given what you are describing I wouldn't bother trying to capture other types of errors. Let what process runs your query handle it. Put your try/catch there and you should be good to go. It sounds like it doesn't matter if the connection times out or the database has been deleted, you want to send 'no_data'.

    Remember that a union is a single query. Parts of it can't work while other parts fail. It is all or nothing.

    select 1

    union all

    select 1 where 1 = 'x' --this query would fail

    Consider the above code. It is a simple query with a union. The second query will cause the whole thing to fail. If you want to capture row counts for each query they need to be run separately. There is no way to know from the results which query in a union returns results.

    Perhaps if you can explain the whole process a little more clearly I can see if I can help figure out a way to get what you want.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/