gpt4 book ai didi

SQL 服务器 2008 : How to select all rows where field has all capital letters?

转载 作者:行者123 更新时间:2023-12-01 11:06:02 26 4
gpt4 key购买 nike

这就是我的想法,我知道在这个字段中,第一个单词总是至少有 2 个字符长。

Select *  
From Table!
where SUBSTRING(Name, 1, 3) like '[A-Z]'

但是,这对带回非大写字母有什么想法吗?

最佳答案

Select ...
From MyTable
Where Name Not Like '%[^A-Z]%' Collate SQL_Latin1_General_CP1_CS_AS

需要注意的是,这也会排除 A-Z 之外的数字和字符。如果您想要包含非拉丁大写字符,您确实需要使用 Upper 函数以及 Collat​​e 谓词:

Select ...
From MyTable
Where Name = Upper(Name) Collate SQL_Latin1_General_CP1_CS_AS

测试脚本:

With TestData As
(
Select '012324' As Name
Union All Select 'ABC'
Union All Select 'abc'
Union All Select 'aBc'
Union All Select 'ABé'
Union All Select 'ABÉ'
)
Select *
From TestData
Where Name = UPPER(Name) Collate SQL_Latin1_General_CP1_CS_AS

结果:

012324
ABC
ABÉ

关于SQL 服务器 2008 : How to select all rows where field has all capital letters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5824359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com