sql query

I have a table field field called zones

Zones has values like
D4.6.D7
D5.Time
Time.D4
5.D4
D8.D4.D8.9
D8.Time.D6
D5.D5.D5
D4




I want to write a query to have only two values lowest and the greatest

D4--lowest
4
D5
5
D6
6
D7
7
D8
8
D9
9
D10
10--highest

]if there is item called time then it should be the only thing in it.All the other option should be removed.

So the result for above data should be

D4.D7
Time
D4.5
D4.9
Time
D5.D5
D4.D4
Angela4evaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SharathData EngineerCommented:
Can you check this query?
SELECT ID, 'D' + CONVERT(VARCHAR, MIN(Col_Part)) + '.D' + CONVERT(VARCHAR, MAX(Col_Part)) Col 
FROM   (SELECT ID, Col, 
               REPLACE(LTRIM(SUBSTRING(Col, n, CHARINDEX('.', Col + '.', n) - n)), 'D', '') AS Col_Part
        FROM   your_table 
               CROSS JOIN (SELECT number 
                           FROM   master..spt_values 
                           WHERE  type = 'P') AS Numbers(n) 
        WHERE  Col NOT LIKE '%Time%' 
           AND SUBSTRING('.' + Col, n, 1) = '.' 
           AND n < LEN(Col) + 1) t1 
GROUP  BY ID, Col 
UNION ALL 
SELECT ID, 'Time' Col 
FROM   your_table 
WHERE  Col LIKE '%Time%' 
ORDER  BY ID 

Open in new window


here is how I tested. http://sqlfiddle.com/#!3/bff29/1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Commented:
>>So the result for above data should be<<
Not really sure what you're asking. Can you provide an explanation as to how you arrive at those results?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.