SQL LIKE operator not showing any result when it should
sql, sql-like, sql-server, t-sql
Solution
Promoted to an answer as requested.
You have some space characters in the end of your Owner field in Vehicle table. '=' operator skips trailing spaces, 'like' operator doesn't.
Problem
I got a Vehicle table with lots of info but one of the columns being 'Owner' in a MSSQL table But one of the owners i can't select when i use `LIKE` but can if i use `=` 'Silkeborg Distributionscenter' is the owner (Yes there is a double space in both the table and the param) So the param is: ``` DECLARE @Owners nvarchar(MAX) = 'Silkeborg Distributionscenter' ``` I tried: ``` SELECT * FROM Vehicle WHERE @Owners = Owner --This gave me all the correct results ``` Then: ``` SELECT * FROM Vehicle WHERE @Owners LIKE Owner --No result ``` Then: ``` SELECT * FROM Vehicle WHERE @Owners COLLATE Danish_Norwegian_CI_AS LIKE Owner COLLATE Danish_Norwegian_CI_AS --No result ``` I need to use LIKE because i need to be able to select a array of owners at once. So the original select statement look like this ``` SELECT * FROM Vehicle WHERE ('|' + @Owners + '|' like '%|' + Owner + '|%') --No result ``` Any Ideas? Edit: It all works fine the @Owners is 'Fredericia Distributionscenter' but not 'Silkeborg Distributionscenter', Both of them is within the table. Is the something work in the 'Silkeborg Distributionscenter' text?