I have to select all fields which contain a specific text and ended with "
, '
, )
or blank space characters or this text is placed in the end of string.
So, I need something like that:
select *
from MyTable
Where Column1 like '%' + @text + '["'') ]%'
This query works fine until text is not placed in the end of Column1
.
You could use
Where Column1 + '"' like '%' + @text + '["'') ]%'
Why not try OR?
Where Column1 like '%' + @text + '["'') ]%'
or
Column1 like '%' + @text + '["'') ]'
Or do I misunderstand the requirement? Your question is a little hard to follow.
SELECT *
FROM MyTable
WHERE Column1 LIKE '%' + @text + '%["'') ]'
OR Column1 LIKE '%' + @text
This should work better and faster:
SELECT * FROM MyTable
WHERE
( (RIGHT(Column1,1) IN (' ', '"', '''', ')'))
AND
(SUBSTRING(Column1, LENGTH(@text)-1, LENGTH(@text))=@text)
)
OR ( RIGHT(Column1, LENGTH(@text))=@text )