beehexa integrationsidebar
beehexa logo

We Build HexaSync Integration Platform for Connecting ERP, POS, CRM, Accounting, and eCommerce Applications to Automate Business Processes

Mysql sever string case sensitive

Microsoft SQL Server string compare case sensitive

Sometimes, your collections of data might contain case sensitive values. In my case, there are several products that have the same Manufacturer but our client misused that data and created duplicated “same” manufacturers without verifying if they exist in the system or not. It leads to an issue that the product might load the incorrect manufacturer every time the application loads its detail. The relationship between product and manufacturer changes too often because of below SQL Script:

/**
* This query returns all products that exists in both 'EERO' and 'eero' manufacturer
**/
DECLARE @ManufacturerName NVARCHAR(255);
SET @ManufacturerName = 'EERO' -- This name is duplicated with 'eero'
SELECT p.* 
FROM products p
INNER JOIN manufacturers m on m.id = p.manufacturer_id
WHERE m.name = @ManufacturerName -- We only need to get which products that have manufacturer of 'EERO' not 'eero'Code language: CSS (css)

To fix the issue, we should add `COLLATE Latin1_General_CS_AS ` as below:

DECLARE @ManufacturerName NVARCHAR(255);
SET @ManufacturerName = 'EERO' -- This name is duplicated with 'eero'
SELECT p.* 
FROM products p
INNER JOIN manufacturers m on m.id = p.manufacturer_id
WHERE m.name = @ManufacturerName COLLATE Latin1_General_CS_AS -- case sensitive comparisonCode language: CSS (css)

That’s it.
Happy coding.

Table of Contents

Ready to integrate and automate at scale ?

Learn how HexaSync lets you build enterprise-grade integrations and automations without having to code.

Receive Exclusive Productivity Tips Directly in Your Inbox

We’ll email you 1-3 times per week—and never share your information.

Get started for free

You can’t add more hours to the day. Beehexa is the next best thing.