Home > Blockchain >  Case sensitive for a specific column
Case sensitive for a specific column

Time:05-17

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

CodePudding user response:

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;
  • Related