I have a lengthy stored procedure that builds a query string. It works fine until I add in a 'LIKE' description field (text) which has a wildcard in it, see below:
IF @AdDescription IS NOT NULL
IF @AdSection IS NOT NULL
BEGIN
SET @SQL = @SQL + @Wand + 'na.Section = '' + @AdDescription + '''
SET @Wand = ' AND '
END
ELSE
BEGIN
SET @SQL = @SQL + @Wand + '(na.AdDesc LIKE ''' + @AdDescription + '%'')'
SET @Wand = ' AND '
END
I've tried a few variations but as soon as @AdDescription has anything in it it fails. Is there something obvious that I am missing?