Search code examples
sql-serverfunctionsql-server-2012raiserror

How to use Function inside a raiserror


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 ?


Solution

  • 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;