views:

38

answers:

4

I am looking to output a message from a function in MS SQL 2005 when executed from the sql server management studio, similar to Postgres' RAISE NOTICE.

+1  A: 

You can raise errors with RAISERROR, or print messages with PRINT. You should look these up in Books Online.

treaschf
+1  A: 

It would be RAISERROR in SQL Server

SQLMenace
+1  A: 

To add to the other answers, you may want to read through these great articles:

Error Handling in SQL 2005 and Later

Frank Kalis
A: 

The direct translation may be RAISERROR, but SQL Server 2005 now supports TRY/CATCH blocks

BEGIN TRY
BEGIN TRANSACTION TestTransaction

INSERT INTO tbBlah
(
    SomeColumn
)
VALUES
(
    5
)

COMMIT TRANSACTION TestTransaction
END TRY

BEGIN CATCH
    ROLLBACK TRANSACTION TestTransaction
END CATCH
Peder Rice