How to escape '%' inside varchar @params for RAISERROR funcion in SQL Server 2012
15
votes
4
answers
13419
views
How I should escape the
%
character in params so my RAISERROR
retun my message
declare @msg varchar(max) = (SELECT ' Message with % ' AS MSG)
if @msg is not null
begin
RAISERROR (@msg ,16,1);
end
This will rise error with message
> Msg 2787, Level 16, State 1, Line 4
> Invalid format specification: '% '.
For end users this message is unreadable.
My messages is generated from database and setting this message.
Way I do avoid getting wrong message is replacing
set @msg = REPLACE(@msg,'%','P')
But I still do not know how to add %
sign
Asked by adopilot
(2443 rep)
Aug 18, 2014, 09:45 AM
Last activity: Jan 25, 2018, 10:11 PM
Last activity: Jan 25, 2018, 10:11 PM