In a test case I’ve written, the string comparison doesn’t appear to work the same way between SQL server / .NET CLR.
This C# code:
string lesser = "SR2-A1-10-90";
string greater = "SR2-A1-100-10";
Debug.WriteLine(string.Compare("A","B"));
Debug.WriteLine(string.Compare(lesser, greater));
Will output:
-1
1
This SQL Server code:
declare @lesser varchar(20);
declare @greater varchar(20);
set @lesser = 'SR2-A1-10-90';
set @greater = 'SR2-A1-100-10';
IF @lesser < @greater
SELECT 'Less Than';
ELSE
SELECT 'Greater than';
Will output:
Less Than
Why the difference?
This is documented here.
Windows collations (e.g.
Latin1_General_CI_AS) use Unicode type collation rules. SQL Collations don’t.This causes the hyphen character to be treated differently between the two.