Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Procedures: Adding directives

Author  Topic 

jeff00seattle
Starting Member

5 Posts

Posted - 2009-01-02 : 13:32:56
Hi

Within a stored procedure, is there a way to add a directive which wraps around a piece of code, thereby that code is only visible if its directive is TRUE?

For example, in DEBUG mode, have code wrapped within a TRY/CATCH block:

Declare @deadline int
set @deadline = 0

BEGIN TRY
SELECT DaysToManufacture / @deadline
from AdventureWorks.Production.Product
WHERE ProductID = 921
END TRY
BEGIN CATCH
EXECUTE usp_GetErrorInfo;
END CATCH;


And in PRODUCTION mode for performance reasons, have TRY/CATCH block not visible to the SQL engine. For example

Declare @deadline int
set @deadline = 0

SELECT DaysToManufacture / @deadline
from AdventureWorks.Production.Product
WHERE ProductID = 921

SELECT usp_GetErrorInfo;


Ideas?


Thanks

Jeff in Seattle

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-02 : 14:09:55
There isn't an easy way to do it. You'd have to have a table that specified what environment it was and then check with an IF statement to determine what to do.

But why do you think that the TRY/CATCH is a performance problem?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -