测试大写 - T-Sql [英] Test for Upper Case - T-Sql

查看:38
本文介绍了测试大写 - T-Sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

如何在 T-Sql 中检查指定的 varchar 字符或整个字符串是否为大写?理想情况下,我想编写一个函数来测试字符是否为大写,然后我可以稍后将其应用于通用 varchar.对于非字母字符,它应该返回 false.我只对英文字符感兴趣.

How can I check if a specified varchar character or entire string is upper case in T-Sql? Ideally I'd like to write a function to test if a character is upper case, then I can later apply that to a generic varchar. It should return false for non alphabetic characters. I am only interested in english language characters.

我正在 SQL Management Studio 中使用 T-sql,并且我尝试以这种方式从表中提取以小写字母开头的记录:

I am working with T-sql in SQL Management Studio, and I have tried pulling records beginning with a lower case letter from a table in this fashion:

select * from TABLE
where SUBSTRING(author,1,1) != LOWER(SUBSTRING(author,1,1))

返回 0 条记录,但我知道有以大写和小写字母开头的记录.

Which returns 0 records, but I know there are records beginning with upper and lower case letters.

谢谢

由于 podiluskajoachim-isaksoon 已经成功回答了我的问题(两种方法都适用于我的目的),有人介意解释一下哪种方法是用于查询表的最有效方法有大量记录要过滤掉作者以大写字母开头还是不以大写字母开头的记录?

Since both podiluska and joachim-isaksoon have successfully answered my question (Both methods work for my purposes), would someone mind explaining which would be the most efficient method to use to query a table with a large number of records to filter out records with authors beginning with or without a capital letter?

推荐答案

使用排序规则

例如:

if ('a'='A' Collate Latin1_General_CI_AI) 
    print'same 1'
else
    print 'different 1'

if ('a'='A' Collate Latin1_General_CS_AI) 
    print'same 2'
else
    print 'different 2' 

归类名称中的 CS 表示区分大小写(和 CI,不区分大小写).AI/AS 与重音敏感度有关.

The CS in the collation name indicates Case Sensitive (and CI, Case Insensitive). The AI/AS relates to accent sensitivity.

或者在你的例子中

SUBSTRING(author,1,1) <> LOWER(SUBSTRING(author,1,1)) COLLATE Latin1_General_CS_AI

这篇关于测试大写 - T-Sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆