Where [CastleType] is set as data type \"text\" in SQL Server and the query is:
SELECT *
FROM [Village]
WHERE [CastleType] = \'foo\'
I
If you can't change the datatype on the table itself to use varchar(max), then change your query to this:
SELECT *
FROM [Village]
WHERE CONVERT(VARCHAR(MAX), [CastleType]) = 'foo'
That is not what the error message says. It says that you cannot use the =
operator. Try for instance LIKE 'foo'
.
Please try this
SELECT *
FROM [Village]
WHERE CONVERT(VARCHAR, CastleType) = 'foo'
This works in MSSQL and MySQL:
SELECT *
FROM Village
WHERE CastleType LIKE '%foo%';
Another option would be:
SELECT * FROM [Village] WHERE PATINDEX('foo', [CastleType]) <> 0
You can use LIKE
instead of =
. Without any wildcards this will have the same effect.
DECLARE @Village TABLE
(CastleType TEXT)
INSERT INTO @Village
VALUES
(
'foo'
)
SELECT *
FROM @Village
WHERE [CastleType] LIKE 'foo'
text
is deprecated. Changing to varchar(max)
will be easier to work with.
Also how large is the data likely to be? If you are going to be doing equality comparisons you will ideally want to index this column. This isn't possible if you declare the column as anything wider than 900 bytes though you can add a computed checksum
or hash
column that can be used to speed this type of query up.