Server在where表达式中忽略大小写

Server在where表达式中忽略大小写

本文介绍了SQL Server在where表达式中忽略大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何构造其中 where子句不区分大小写的SQL查询(MS SQL Server)?

  SELECT * FROM myTable WHERE myField ='sOmeVal'

我希望结果返回而忽略大小写

解决方案

在SQL Server数据库的默认配置中,字符串比较 不区分大小写。如果数据库覆盖此设置(通过使用替代排序规则),则需要指定在查询中使用哪种排序规则。

  SELECT *从myTable到myField ='sOmeVal'COLLATE SQL_Latin1_General_CP1_CI_AS 

我提供的排序规则只是一个示例(尽管它可能对您来说很可能起作用)。可以在找到更完整的SQL Server排序规则概述。。 p>

How do I construct a SQL query (MS SQL Server) where the "where" clause is case-insensitive?

SELECT * FROM myTable WHERE myField = 'sOmeVal'

I want the results to come back ignoring the case

解决方案

In the default configuration of a SQL Server database, string comparisons are case-insensitive. If your database overrides this setting (through the use of an alternate collation), then you'll need to specify what sort of collation to use in your query.

SELECT * FROM myTable WHERE myField = 'sOmeVal' COLLATE SQL_Latin1_General_CP1_CI_AS

Note that the collation I provided is just an example (though it will more than likely function just fine for you). A more thorough outline of SQL Server collations can be found here.

这篇关于SQL Server在where表达式中忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:29