Identify if a string is uppercase in sql server!

6

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?

    
asked by Rafael Dantas 02.06.2017 в 19:24
source

1 answer

8

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

    
answered by 02.06.2017 / 19:29
source