I have the following code below:
BEGIN TRY
BEGIN TRANSACTION
-- DO SOMETHIING
COMMIT TRAN
END TRY
BEGIN CATCH
IF(@@TRANCOUNT > 0)
ROLLBACK TRANSACTION
RAISERROR(ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE()) --ERROR: Incorrect syntax near 'ERROR_MESSAGE'.
END CATCH
However, the RAISERROR statement isn’t working. What is wrong in the raise error statement?
RAISERROR follows the same rules as any other stored procedure call. Parameters passed in must be a constant or a variable. You cannot pass a function directly as a parameter. See Executing Stored Procedures for documentation on this.