I’m comparing text values in the same table and same column in SQL Server 2008, but the results are sometimes incorrect. Possibly relevant column info:
Data type: text
Full Text: True
Collation: SQL_Latin1_General_CP1_CI_AS
Out of 100 actual matches I only get 62. I have compared field values that are not picked up by LIKE in some comparison tools and they are 100% same, no additional spaces, line breaks etc.
Any idea why text LIKE doesn’t always work?
SQL:
SELECT a.text as one, b.text as two
FROM [Db].[dbo].[Table] a join
[Db].[dbo].[Table] b on
a.text LIKE b.text
The following two examples show
LIKEworking exactly as expected. I suspect the reason you say “LIKEdoesn’t always work” is because you don’t know howLIKEworks.Here’s an example where one match should occur:
“
Hellois likeHello,” you say.Here’s a match where no matches should occur:
“But
[h]is like[h],” you say.LIKEis not the equality operator, it has a special syntax for searching for single characters, ranges of characters and variable numbers of characters. If you happen to feed it text in a column that uses that special syntax (intentionally or not), it will treat the special syntax as character matching instructions, not as literal text.