How to use Function inside a raiserror

106 Views Asked by At

This is what I have tried, but seems to be wrong.

CREATE PROCEDURE test_proc(@User VARCHAR = NULL)
AS
BEGIN

RAISERROR (Select F_GetAmandaMessage('SAMPLE_TEST_KEY',NULL,@User), 16, 1);

END;

Could you please guide me here

Should I store the result of the function in a variable first and then use that variable in the raiserror section ?

1

There are 1 best solutions below

1
On BEST ANSWER

You must use a message id, a string literal or a variable in RAISERROR

CREATE PROCEDURE test_proc(@User VARCHAR = NULL)
AS
BEGIN
DECLARE @Message varchar(128) = (
   SELECT F_GetAmandaMessage('SAMPLE_TEST_KEY', NULL, @User)
);

RAISERROR(@Message, 16, 1);

END;