简体   繁体   中英

Case sensitive for a specific column

I am using Microsoft SQL Management Studio V18. I have a column where I need to find if it contain any lower case alphabets. See below for desired output:

Material# Material_Desc Contain_Lower
123 PRODUCT DESCRIPTION Yes
213 Product Description No

Since the default collation is case insensitive I just want to turn it on for that specific column.

I've tried the following however it does not work - it does not identify if row2 contain a lower case alphabet. What can I do to identify if the column has a lower case?

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

You are on the right way, but you just forced the column to UPPER CASE. You also need to compare:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM