SQL Case Sensitive String Compare
Select * from a_table where attribute = 'k' COLLATE Latin1_General_CS_AS
Did the trick.
Case Sensitive String Comparison
SQL Server has case sensitivity at the server, database, and column level. This is part of the collation properties. So in your example, it's likely that one or more of these settings has been set to case-insensitive.
-- Check server collation
SELECT SERVERPROPERTY('COLLATION')
-- Check database collation.
SELECT DATABASEPROPERTYEX('AdventureWorks', 'Collation') SQLCollation;
-- Check column collation
select table_name, column_name, collation_name
from information_schema.columns
where table_name = @table_name
Something like this SQL might work for you:
If (@USERNAME='rajat' COLLATE Latin1_General_CS_AS)
.....
How to do like compare on case sensitive string
The default should be case sensitive, as explained in the documentation:
path like '%login%'
For case-insensitive, use ilike
:
path ilike '%login%'
SQL- Ignore case while searching for a string
Use something like this -
SELECT DISTINCT COL_NAME FROM myTable WHERE UPPER(COL_NAME) LIKE UPPER('%PriceOrder%')
or
SELECT DISTINCT COL_NAME FROM myTable WHERE LOWER(COL_NAME) LIKE LOWER('%PriceOrder%')
How can I make SQL case sensitive string comparison on MySQL?
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:
col_name COLLATE latin1_general_cs LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_general_cs
col_name COLLATE latin1_bin LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_bin
If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation.
SQL ORDER BY a string value: What is it comparing? (Case sensitive?)
In MySQL, it depends on the effective collation. Collation is the set of rules that determine the position of characters in an ordered set and what characters are considered equal, and typically involve natural language rules. For example, Spanish used to have ch
as an independent letter located betwen c
and d
and then switched to being just individual c
and h
; MySQL has collations for both.
You can see available collations with these commands:
SHOW COLLATION; -- Display all
SHOW COLLATION WHERE charset = 'utf8mb4'; -- Filter by encoding
Collation | Charset | Id | Default | Compiled | Sortlen | Pad_attribute |
---|---|---|---|---|---|---|
utf8mb4_0900_ai_ci | utf8mb4 | 255 | Yes | Yes | 0 | NO PAD |
utf8mb4_0900_as_ci | utf8mb4 | 305 | Yes | 0 | NO PAD | |
utf8mb4_0900_as_cs | utf8mb4 | 278 | Yes | 0 | NO PAD | |
utf8mb4_0900_bin | utf8mb4 | 309 | Yes | 1 | NO PAD | |
utf8mb4_bin | utf8mb4 | 46 | Yes | 1 | PAD SPACE | |
utf8mb4_croatian_ci | utf8mb4 | 245 | Yes | 8 | PAD SPACE | |
utf8mb4_cs_0900_ai_ci | utf8mb4 | 266 | Yes | 0 | NO PAD | |
utf8mb4_cs_0900_as_cs | utf8mb4 | 289 | Yes | 0 | NO PAD | |
utf8mb4_czech_ci | utf8mb4 | 234 | Yes | 8 | PAD SPACE | |
utf8mb4_danish_ci | utf8mb4 | 235 | Yes | 8 | PAD SPACE |
Case-sensitive string comparison in SQL (MariaDB, MySQL)
This should work:
WHERE BINARY column = 'data'
However, it will not work if you put column
in single quotes. That would be a string as opposed to a column reference.
SQL case sensitive string comparison with like and =
Use upper function.
SELECT * FROM category WHERE upper(cat_name) = upper('Test')
Related Topics
SQL - How to Store and Navigate Hierarchies
Group by to Combine/Concat a Column
How to Use Variables in Oracle SQL Developer
Spark SQL Window Function With Complex Condition
How to Create a Sequence in MySQL
MySQL Query to Select Data from Last Week
MySQL, Better to Insert Null or Empty String
How to Create a Unique Index on a Null Column
Top N Records Per Group SQL in Access
Can a Check Constraint Relate to Another Table
Unknown Column in 'Field List' Error on MySQL Update Query
Calculating Distance Between Two Points (Latitude, Longitude)
How to Select from Subquery Using Laravel Query Builder
Group by Behavior When No Aggregate Functions Are Present in the Select Clause
SQL Server - in Clause With a Declared Variable
SQL Server 2005 How Create a Unique Constraint
How to Check If a Column Is Empty or Null in MySQL
Why "Extra Characters After Command" Error Shown for the Sed Command Line Shown