SQL搜索具有text数据类型的字段中的值,而不考虑大小写

Mic*_*son 1 sql-server select text lowercase

我试图获得特定搜索的所有值,而不管套管.在我们的SQL Server数据库上,启用了案例敏感性,如果可能,我不想更改此问题.

如果我执行包含LOWER()函数的SELECT语句,如下所示

SELECT COUNT(blogpostId) as blogpostcount
FROM blogposts
WHERE stateId = '1'
AND blogId = '20'
AND LOWER(blogpostContent) LIKE '%test%'
Run Code Online (Sandbox Code Playgroud)

它会引发错误

参数数据类型文本对于较低函数的参数1无效.

blogpostContent列的数据类型是text.如果我将其更改为此nvarchar作品但是nvarchar只允许最多255个字符,我需要的不仅仅是这个.

无论如何都要在文本字段中检查结果而不管套管?

提前致谢

p.c*_*ell 6

您可以明确强制它使用CASE INSENSITIVE排序规则,如下所示:

SELECT COUNT(blogpostId) as blogpostcount  
FROM blogposts  
WHERE stateId='1'  
AND blogId = '20'  
AND blogpostContent LIKE '%test%'  COLLATE SQL_Latin1_General_CP1_CI_AS 
Run Code Online (Sandbox Code Playgroud)