Not sure if I understand the situation correctly, but if the uniqueness must be enforced using case sensitive comparison, I would prefer defining that logic to the table. Modifying the insert statement to correctly handle the collation sounds risky.
So why not define the collation for the column that is defined as unique. Consider the following example where
CSData
column uses case sensitive uniqueness and
CIData
case-insensitive.
CREATE TABLE CollateTest (
CSData nvarchar(100) COLLATE Latin1_General_CS_AS,
CIData nvarchar(100) COLLATE Latin1_General_CI_AI
);
ALTER TABLE CollateTest
ADD CONSTRAINT UQ_CollateTest_CSData UNIQUE (CSData);
ALTER TABLE CollateTest
ADD CONSTRAINT UQ_CollateTest_CIData UNIQUE (CIData);
INSERT INTO CollateTest (CSData, CIData) VALUES ('AAA', 'Test1');
INSERT INTO CollateTest (CSData, CIData) VALUES ('AAa', 'Test2');
INSERT INTO CollateTest (CSData, CIData) VALUES ('AAA', 'Test3');
INSERT INTO CollateTest (CSData, CIData) VALUES ('Test1', 'AAA');
INSERT INTO CollateTest (CSData, CIData) VALUES ('Test2', 'AAa');
INSERT INTO CollateTest (CSData, CIData) VALUES ('Test3', 'AAA');