SELECT query ordering by substring in Sql Server -


I have a column in the SQL Server table that contains the following lines:

MyColumn: < / P>

  1 month 2 weeks 10 minutes 1 week 12 hours 1 day 2 months 2 days 5 minutes 1 hour   

This is a text column that contains the priority string .

Is there a way to get rid of this selection, this column has been ordered as following:

  10 minutes 5 minutes 1 hour 10 hours 1 day 2 days 1 week 2 weeks 1 month 2 months ago  

Try this solution:

  SELECT mycolumn from Tbl ORDER by SUBSTRING (mycolumn, PATINDEX ('% [^ 0-9]%', 'itemprop = "text"> 

Mycolumn) +1, 999, CAST (LEFT (mycolumn, PATINDEX ('% [^ 0-9]%', mycolumn) -1) INT



Comments