在 MS 中强制 T-SQL 查询区分大小写
我有一个源自旧遗留系统的表,该系统区分大小写,特别是状态列,其中“s”=“计划导入”和“S”=“计划管理”。该表最终进入 SQL Server 2000 数据库,我可以对其进行查询。我的查询相对简单,只是进行计数...
Select trans_type, count(1) from mytable group by trans_type
这将“S”的计数与“s”的计数分组。有没有办法强制查询对大小写敏感?我可以访问 SQL Server 2000 和 2005 环境来运行它,但是服务器上的管理能力有限(所以我无法设置服务器属性)...我想我可以将数据移动到本地并在在我的本地,我可以完全访问服务器选项,但更喜欢 tsql 解决方案。
I have a table that originates in an old legacy system that was case senstive, in particular a status column where 's' = 'Schedule import' and 'S' = 'Schedule management'. This table eventually makes its way into a SQL Server 2000 database which I can query against. My query is relatively simple just going for counts...
Select trans_type, count(1) from mytable group by trans_type
This is grouping the counts for 'S' along with the 's' counts. Is there any way to force a query to be cap sensitive? I have access to both SQL Server 2000 and 2005 environments to run this, however have limited admin capability on the server (so I can't set server attributes)... I guess I could move the data to my local and setup something on my local where I have full access to server options, but would prefer a tsql solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以使用
=
、like
和其他运算符来完成此操作。请注意,您必须修改选择列表,因为您不再按trans_type
分组,而是按trans_type collate SQL_Latin1_General_CP1_CS_AS
分组。有点陷阱。You can do this with
=
,like
, and other operators as well. Note that you must modify the select list because you are no longer grouping bytrans_type
, you are now grouping bytrans_type collate SQL_Latin1_General_CP1_CS_AS
. Kind of a gotcha.您能否引入一个 trans_type_ascii 列,其中包含 trans_type 的 ascii 值并对其进行分组?或者您可以使用 (isUpperCase) 来区分它们的任何其他列。
Can you introduce a trans_type_ascii column with the ascii value of the trans_type and group on that instead? Or any other column you can use (isUpperCase) to distinguish them.