Feeds:
Posts
Comments

Archive for May, 2018

SQL to escape all SQL wildcard characters in a string:

DECLARE @DirtyString nvarchar(1000) = ‘How\now % [brown_cow]’;
DECLARE @CleanString nvarchar(1000);

SET @CleanString = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@DirtyString, ‘\’, ‘\\’, ‘%’, ‘\%’), ‘_’, ‘\_’), ‘[‘, ‘\[‘), ‘]’, ‘\]’);

PRINT ‘@CleanString = ‘ + @CleanString;

Advertisements

Read Full Post »