4

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.

Tom Ritter
  • 99,986
  • 30
  • 138
  • 174

2 Answers2

17

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

kristof
  • 52,923
  • 24
  • 87
  • 110
  • 1
    I realise that your arguments look more like BIT data type rather then INT but it seems that BIT is not supported as a valid type for building the message string – kristof Oct 22 '08 at 16:07
0

I use raiserror a lot. We have some stored procedures that are called from a .Net app each night for batch processing, and the .Net app wants to log the procedure output this way. I don't know why, but I generally have to build the string before calling raiserror.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794