I have a field in a table that must be filled in all lowercase, but the user being user has filled some lines in uppercase. I want to identify which records are in order to request correction.
How can I test if my string is all uppercase?
I have a field in a table that must be filled in all lowercase, but the user being user has filled some lines in uppercase. I want to identify which records are in order to request correction.
How can I test if my string is all uppercase?
You can use COLLATE LATIN1_GENERAL_CS_AI
in your validation as follows:
DECLARE @texto_normal VARCHAR(100);
DECLARE @texto_minusculo VARCHAR(100);
SET @texto_normal = 'Normal';
SET @texto_minusculo = 'minusculo';
IF LOWER(@texto_normal) <> @texto_normal COLLATE LATIN1_GENERAL_CS_AI
BEGIN
PRINT '@texto_normal tem maiúsculas';
END;
IF LOWER(@texto_minusculo) <> @texto_minusculo COLLATE LATIN1_GENERAL_CS_AI
BEGIN
PRINT '@texto_minusculo tem maiúsculas';
END;
Or to use in a query
:
SELECT *
FROM tabela t
WHERE LOWER(t.campo) <> t.campo COLLATE LATIN1_GENERAL_CS_AI;
The CS_
in the selector says that the text is case sensitive
.
Reference: Collation and Unicode Support