I have a comma delimited string that I need to break into array ranges that can be passed into SQL server's BETWEEN statement.
For instance, say I have the following string below, I need the corresponding returnVal returned;
string delimited = "1,2,5,6,7,8,11,12,13,15,16,17,18,19";
returnVal = int[,] ranges = new int[4, 2] { { 1, 2 }, { 5, 8 }, { 11, 13 }, { 15, 19 } };
My SQL Between Statement would then look like
WHERE (ID BETWEEN 1 AND 2) OR (ID BETWEEN 5 AND 8) OR (ID BETWEEN 11 AND 13) OR (ID BETWEEN 15 AND 19)
Rather than
WHERE ID IN(1,2,5,6,7,8,11,12,13,15,16,17,18,19)
My actual delimited string is over 5000 IDs so I need to use BETWEEN statements rather than IN statements for efficiency.
What would be the most efficient way to do this using C#?