In the where condition, use column names. You cannot vary a column using a variable. So this:
where @target Like @prefixText +'%' ORDER BY DoctorName Asc
should be like
where columnname Like @prefixText ORDER BY DoctorName Asc
Also depending where the variable
prefixtext
is coming, add the % to the end of the variable or let the user add it, don't put it in the statement directly. So before the select you could have something like:
set @prefixtext = @prefixtext + '%'
If you want to vary the statement using variables you should put the SQL text into a string variable and then use the target variable to add relevant column. Like:
SET @sqlText = 'SELECT TOP...WKERE ' @target + ' LIKE...'
And then use
EXECUTE[
^] to run the statement.