SQL query to return only if upper case

1

I would like to make a query in a column and that the return would be only the capitalized words that match the searched criteria (user input), regardless of whether the criteria was typed in uppercase or lowercase.

CREATE PROCEDURE uspConsultaSobrenome

@Sobrenome nvarchar(MAX)

AS
   BEGIN

   SELECT

   SobrenomeID, 
     Sobrenome  
        FROM
            tbl_Sobrenomes
        WHERE 
        Sobrenome LIKE @Sobrenome + N'%'
END

I did so and the answer is both lower case and upper case.

    
asked by anonymous 26.03.2017 / 22:23

1 answer

2

By default the collation of the tables is case insensitive, to know more about collation click here , so you have two alternatives: or change the collation of your column in your table

alter table Foo alter column Bar ntext collate Latin1_General_CS_AS

or run the query by specifying a case sensitive collation

select * from nomes where nome COLLATE Latin1_General_CS_AS ='fulano' 
    
27.03.2017 / 14:05