If [column1] is indexed, the next query may use index:
SELECT * FROM [table] WHERE [column1] LIKE 'starts%'
If I introduce a variable, the query below will never use index:
DECLARE @starts nvarchar(100)
SET @starts = 'starts%'
SELECT * FROM [table] WHERE [column1] LIKE @starts
I want to implement StartsWith search based on user input and i'm not sure what way to choose:
escape user input properly for LIKE so optimizer will be able to pick a plan based on literal
use WITH(FORCESEEK)
- use OPTION (RECOMPILE)