特定列区分大小写
Case sensitive for a specific column
我正在使用 Microsoft SQL Management Studio V18。我有一个列,我需要在其中查找它是否包含任何小写字母。请参阅下面的所需输出:
Material#
Material_Desc
Contain_Lower
123
PRODUCT DESCRIPTION
Yes
213
Product Description
No
由于默认排序规则不区分大小写,我只想为该特定列打开它。
我尝试了以下方法,但它不起作用 - 它无法识别 row2 是否包含小写字母。如何确定该列是否为小写?
select
table.Material_Desc,
Case when
table.Material_Desc collate SQL_Latin1_General_CP1_CS_AS = table.Material_Desc
Then 'No' else 'Yes' end as Contain_Lower
from table
您的方法是正确的,但您只是将列强制为大写。您还需要比较:
SELECT
material_desc,
CASE WHEN material_Desc = UPPER(material_desc) COLLATE SQL_Latin1_General_CP1_CS_AS
THEN 'No' ELSE 'Yes' END AS contain_lower
FROM table;
我正在使用 Microsoft SQL Management Studio V18。我有一个列,我需要在其中查找它是否包含任何小写字母。请参阅下面的所需输出:
Material# | Material_Desc | Contain_Lower |
---|---|---|
123 | PRODUCT DESCRIPTION | Yes |
213 | Product Description | No |
由于默认排序规则不区分大小写,我只想为该特定列打开它。
我尝试了以下方法,但它不起作用 - 它无法识别 row2 是否包含小写字母。如何确定该列是否为小写?
select
table.Material_Desc,
Case when
table.Material_Desc collate SQL_Latin1_General_CP1_CS_AS = table.Material_Desc
Then 'No' else 'Yes' end as Contain_Lower
from table
您的方法是正确的,但您只是将列强制为大写。您还需要比较:
SELECT
material_desc,
CASE WHEN material_Desc = UPPER(material_desc) COLLATE SQL_Latin1_General_CP1_CS_AS
THEN 'No' ELSE 'Yes' END AS contain_lower
FROM table;