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?
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.
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)How to post your question to get the best and quick help