how can I convert this code:
SELECT * FROM DB
WHERE field LIKE N'%'+RTRIM(LTRIM('98'))+N'%'
to:
SET @stringWhere= ' SELECT * FROM DB AND field LIKE '+N'%' +RTRIM(LTRIM(@field))+ N'%';
how can I convert this code:
SELECT * FROM DB
WHERE field LIKE N'%'+RTRIM(LTRIM('98'))+N'%'
to:
SET @stringWhere= ' SELECT * FROM DB AND field LIKE '+N'%' +RTRIM(LTRIM(@field))+ N'%';
Kind of guessing here. Please the code below. And make sure you look at the comments in the code as there are several things that could use improvement.
declare @field nvarchar(10) = N'98'
select * --don't use *, select ONLY the columns you need
from DB
where Name like '%' + @field+ '%' --be careful here, this is a nonSARGable predicate with the leading wildcard. As such all indexes will be rendered useless.