I am trying to search for any string that contains ";" in a column of a table which results in some weird results.
It is not only returning me the results that have ";" but also returns those rows which don't contain any ";" but instead contains a "'".
Here is my query:
select * from fields where Comment like '%;%'
and returned results is
Row 1 & 2 instead of 3 & 4 records
Any idea?
I am adding following table structure and some insert statements for reference. Though the result will differ now
>/****** Object: Table [dbo].[Fields] Script Date: 08/10/2010 14:18:56 ******/ SET ANSI_NULLS ON GO >SET QUOTED_IDENTIFIER ON GO >SET ANSI_PADDING ON GO >CREATE TABLE [dbo].[Fields]( [ID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, [Comment] [text] NULL, ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO >SET ANSI_PADDING OFF GO >INSERT INTO Fields (Comment) VALUES ('Moody''s Corp') Go >INSERT INTO Fields (Comment) VALUES ('0% as core business is ex-growth and hasn''t grown in a decade.') Go >INSERT INTO Fields (Comment) VALUES ('bphivgcofc ;') Go >INSERT INTO Fields (Comment) VALUES ('Newsflow - recommendations on use of paracetamol. Will probably takeoff EPS; in a worst-case but low probability scenario could be a 3% hit to earnings.') Go
------- SOLVED -----
I think the problem is within the interface I am using to query the database. This database is externally hosted so the provider has given us an interface to access that data and it seems there is a problem in that interface.
Thanks for everyone's help and suggestions.