Question about string formatting

  • we know that when using RaiseError function, the function supports providing parameters to subsititute the optional parameters in the system error message (which uses %s, %d ... for parameters).

    So it uses a feature like (C printf standard), but how can we afford such thing without string manipulation?

    becacuse i need to get an error message and format it manually without calling RAISERROR.

  • Read about the FORMATMESSAGE function in BOL.

    Constructs a message from an existing message in sys.messages. The functionality of FORMATMESSAGE resembles that of the RAISERROR statement. However, RAISERROR prints the message immediately, while FORMATMESSAGE returns the formatted message for further processing.

    ...

    This example uses a hypothetical message 50001 stored in sys.messages as, "The number of rows in %s is %1d." FORMATMESSAGE substitutes the values Table1 and 5 for the parameter placeholders. The resulting string, "The number of rows in Table1 is 5," is stored in the local variable @var1.

    DECLARE @var1 VARCHAR(100)

    SELECT @var1 = FORMATMESSAGE(50001, 'Table1', 5)

    SQL = Scarcely Qualifies as a Language

  • Thank you very much, that's really what i need.

    I searched for hours i did not find anything about it.

    Best Regards.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply