|
I have a table as: ID Nu 1 1,2,3,6,7,8,15,16 I need to show it as sequential group like: From To 1-3 , 6-7 , 9-9 , 15-16
(comments are locked)
|
|
Edit: This problem was too interesting to forget about. It took me awhile, but I combined dportas's solution with my function. The result is at the bottom of this answer. Okay. I converted (a limited version of) the stored procedure to a function. If the values are delimited in a single column, use this to convert to a table and then use dportas's solution.
Here's the sample data I used:
Once you have the function, here's how you call it. You'll need to change @tbl and @Numbers to work for your database.
Here's the result:
(comments are locked)
|
|
Assuming you have these numbers as rows in you table then try: Great solution if the numbers are in rows. If they aren't, you could use my InsertListIntoTable sproc (sorry for self-promotion, but the code is an answer to another question: http://ask.sqlservercentral.com/questions/452/how-do-i-insert-or-update-an-array-of-values-without-iteration/510#510). Hmm ... I think I'll write a table function version of the sproc.
Oct 21 '09 at 01:06 PM
Tom Staab
(comments are locked)
|
|
This is like the question at Stack Overflow. Seems my answer is now used on their site, and presumably this one too!
(comments are locked)
|


Don't you mean 1-3,6-8,9-14,15,16?