March 18, 2013 at 12:41 am
Hi,
I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?
Thanks,
Akber.
March 18, 2013 at 3:24 am
akberali67 (3/18/2013)
Hi,I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?
Thanks,
Akber.
To return a message to caller during T-SQL code execution you can use PRINT command.
To throw an error use RAISERROR, together with using BEGIN TRY .. CATCH, it will immediately re-direct code into error handling section.
Problem with PRINT, is that the message is not guaranteed to be returned at the exact moment of execution of the command, as it has a low processing priority, you may find that messages are returned at the end of the whole code execution.
RAISERROR causes immediate termination of the process when used with TRY ... CATCH.
There is one more option:
RAISERROR ('Return message immidiately', 10,1) WITH NOWAIT;
The above command raises error with such low severity which doesn't transferring control to the CATCH block making RAISERROR to behave exactly as PRINT (you can use formatting capability of RAISERROR there). WITH NOWAIT hint makes this command to execute with highest priority, so you will get message back as soon as execution hits this line.
March 18, 2013 at 2:06 pm
akberali67 (3/18/2013)
Hi,I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?
Thanks,
Akber.
The easiest thing to put at the top would be a simple select query referencing a table that does not exist.
Something like SELECT * FROM Table_That_Does_Not_Exist
.
March 18, 2013 at 2:21 pm
sestell1 (3/18/2013)
akberali67 (3/18/2013)
Hi,I have a query window with a lot of code but I do not want to run it entirely in error, is there something I can place in the beginning of the code that will throw me a message?
Thanks,
Akber.
The easiest thing to put at the top would be a simple select query referencing a table that does not exist.
Something like
SELECT * FROM Table_That_Does_Not_Exist
.
I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
March 18, 2013 at 9:53 pm
Thanks so much for all the help, I really appreciate your time. The select statement seems to be the most risk free ofcourse and works best for me. Cheers!
March 19, 2013 at 7:05 am
CapnHector (3/18/2013)
I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.
Simple and effective, I like it!
March 19, 2013 at 7:57 am
sestell1 (3/19/2013)
CapnHector (3/18/2013)
I always use a close parentheses ")" at the top of my code sheets (be careful if you add a go it may not work exactly, tend not to break any thing into batches except in roll out scripts.) This generates a parse error and stops the batch from running.Simple and effective, I like it!
That or SELECT * FROM FakeTable will only stop single batch from executing if your script has multiple batches (separated by GO), only the one will be terminated by having such "parse" errors, other batches will not be affected.
If you want to terminate your script for sure use high severity error:
RAISERROR ('Stop here',20,1) WITH LOG
Nothing will pass the above;-)
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply