Using LIKE in a SQL Server stored procedure
Posted on 2013-10-25
I have a stored procedure which works perfectly when an = condition is used = e.g.
WHERE [Product Code] = @PartNumber AND StbBranchId = @Branch
In order to do some more advanced manual selection in the application I wanted to use
WHERE [Product Code] LIKE @PartNumber AND StbBranchId = @Branch
and for the user to enter something like A1% in the parameter string
Now in a normal query if I say:-
WHERE (stmas.[Product Code] LIKE 'a1%') AND (StBranchDets.StbBranchId = 1)
it works perfectly, but not in the SP
I have even tried:-
WHERE [Product Code] LIKE '+@PartNumber+' AND StbBranchId = @Branch
but no difference.
Any ideas anyone?