How can I create a concatenated message in a SQL Server throw?
You cannot concatenate strings inside a THROW
statement.
What you need to do is create a variable and assign your whole error message to it:
DECLARE @Message NVARCHAR(100)
SET @Message = N'Question result is ''' + @CurrentResult + '''. It should be unmarked or incorrect?'
IF (@CurrentResult != 'N' AND @CurrentResult != 'F')
THROW 50002, @Message, 1
Edited to reflect setting message variable first:
DECLARE @Message varchar(100)
SET @Message = 'Question result is ' + cast(@CurrentResult, varchar(100)) + '. It should be unmarked or incorrect.'
IF (@CurrentResult != 'N' AND @CurrentResult != 'F')
THROW 50002,@Message,1
Casting to varchar will keep the text value of whatever @CurrentResult
is. Set the size accordingly.