I need to do some in-memory merging in C# of two sorted streams of strings coming from one or more SQL Server 2000 databases into a single sorted stream. These streams of data can be huge, so I don't want to pull both streams into memory. Instead, I need to keep one item at a time from each stream in memory and at each step, compare the current item from each stream, push the minimum onto the final stream, and pull the next item from the appropriate source stream. To do this correctly, though, the in-memory comparison has to match the collation of the database (consider the streams [A,B,C]
and [A,B,C]
: the correct merged sequence is [A,A,B,B,C,C]
, but if your in-memory comparison thinks C < B
, your in-memory merge will yield A,A,B
, at which point it will be looking at a B
and a C
, and will yield the C
, resulting in an incorrectly sorted stream.)
So, my question is: is there any way to mimic any of the collations in SQL Server 2000 with a System.StringComparison
enum in C# or vise-versa? The closest I've come is to use System.StringCompaison.Ordinal
with the results of the database strings converted to VARBINARY
with the standard VARBINARY
ordering, which works, but I'd rather just add an "order by name collate X"
clause to my SQL queries, where X is some collation that works exactly like the VARBINARY
ordering, rather than converting all strings to VARBINARY
as they leave the database and then back to strings as they come in memory.