Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you continue SQL query when found error?

How can you continue SQL query when found error while querying?

I want to continue a query if any error will occur. I want to get the output of a certain statement and want to see if what is the last output of the query.

How can you do it in T-SQL?

like image 629
ajdeguzman Avatar asked Jun 20 '13 09:06

ajdeguzman


People also ask

How do you continue a line in SQL?

SQL statements can be contained on one or more lines. To continue an SQL statement across multiple lines, the SQL statement can be split wherever a blank is allowed. The plus sign (+) can be used to indicate a continuation of a string constant. The literal continues with the first nonblank character on the next line.

How do I catch an error message in SQL Server?

When called in a CATCH block, ERROR_MESSAGE returns the complete text of the error message that caused the CATCH block to run. The text includes the values supplied for any substitutable parameters - for example, lengths, object names, or times. ERROR_MESSAGE returns NULL when called outside the scope of a CATCH block.


1 Answers

You can use a TRY-CATCH for error handling.

You can find enough documentation here : http://msdn.microsoft.com/en-us/library/ms175976.aspx

UPDATE:

After a bit more research I have found that using a GO command will allow you to continue to your next query, and you won't have to restructure your entire code with TRY-CATCH statements. I still recommend using TRY-CATCH statements to control errors, but just use GO between them.

This is the link where I found the answer: continue-executing-sql-statements-despite-errors

like image 102
Radu Gheorghiu Avatar answered Oct 08 '22 21:10

Radu Gheorghiu