Thanks for responding, Eirikur. I've been racking my brain over this for a couple weeks now. Looking at the code, I don't think it will do what I need.
Given @SerialNumber = '6100,6102,6106,6107-6117,6131,6156,6200-6299,6451,6006,5990-5999,6001'
Output should be:
Serial
====
6100
6102
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6131
6156
6200
6201
6202
...
6297
6298
6299
6451
6006
5990
5991
5992
...
5997
5998
5999
6001
As of now, my code will output the following:
Serial
====
6100
6102
6106
6107-6117
6131
6156
6200-6299
6451
6006
5990-5999
6001
I should add that this is being used as a filter to select existing records. The @SerialTable is JOINed to the actual table that I'm trying to filter from. So, I'm thinking for the second part, I take any rows from @SerialTable which has a '-' in the Serial field, put together a query like "SELECT t.SerialNumber FROM DataTable t WHERE (t.SerialNumber BETWEEN 6107 AND 6117) OR (t.SerialNumber BETWEEN 6200 AND 6299) OR (t.SerialNumber BETWEEN 5990 AND 5999)". Then I would need to remove any rows in @SerialTable which contains '-'. I just don't know how I should write the SQL to take those rows from @SerialTable and build the WHERE clause for it. I am able to use Dynamic SQL, and I think that's the easiest way.
Hope this helps.