I am attempting to use CollationInfo.Comparer from SMO to get my c# code to sort like SQL Server. I have gotten the correct collation, but my items still do not sort correctly.
var collationInfo = CollationInfo.Collations.Single(x => x.Name == "SQL_Latin1_General_CP1_CS_AS") as CollationInfo;
var comparer = collationInfo.Comparer;
int c = comparer.Compare("Tri-Valley L", "Trimble L");
In this case c returns '1' indicating that Tri-Valley L will come after Trimble.
However this code in SQL Server
DECLARE @T TABLE
(
Name VARCHAR(20)
)
INSERT INTO @T
(
Name
)
VALUES('Tri-Valley L'),
('Trimble L')
SELECT
Name
FROM
@T
ORDER BY Name
Returns Tri-Valley before Trimble.
Does the collation compare stuff just not work correctly, or am I doing something wrong?
ORDER BY Name COLLATE SQL_Latin1_General_CP1_CS_AS
, does it still sort in the same order? – Crabby