Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raiseerror and Concat for the Message

I'd like to do something like this

raiserror(concat('Error in case @isFishy =', @isFishy, ' @isSmarmy=', @isSmarmy, ' @isTasty = ', @isTasty), 10, 1)
--or
raiserror('Error in case @isFishy =' + @isFishy + ' @isSmarmy=' + @isSmarmy + ' @isTasty = ' + @isTasty, 10, 1)

But it just isn't working. How do I accomplish this? I'm in SQL Server 2005.

like image 751
Tom Ritter Avatar asked Dec 04 '22 16:12

Tom Ritter


1 Answers

The error message in RAISERROR has actually similar syntax to printf function in C, so assuming your arguments are of the type of integer you would need to use:

raiserror(N'Error in case @isFishy = %d @isSmarmy = %d @isTasty = %d',10,1,@isFishy,@isSmarmy,@isTasty)

check out BOL for details and other options

like image 123
kristof Avatar answered Jan 08 '23 08:01

kristof