Friday 15 January 2010

sql server 2008 - Arrange column with both numeric and hyphenated values -


I'm trying to organize a column with values ​​such as:

  6-3 11 -1 3 8-5 5 6-2 1 7 11-4 8-12 2 I want to organize them like this:  < <>  1 2 3 5 7 6-2 6-3 8-5 8-12 11-1 11-4   

I now have this question: < Pre> select column_name from database_name.dbo.table_name (when BOX_NO is not like '% -%') then -1 when (like BOX_NO '% -%') is inserted again (SUBSTRING (reverse (BOX_NO) LAX (BOX_NO) - ('-', reverse (BOX_NO) - 2), 0) as ET), (when the column_name is not like '% -%' Then insert ('-%') as cast ('-%') then cast (asbestring (column_name, ln (column_name) - (CHARINDEX ('-', reverse (column_name)) - 2), 8000) interval In form)

I am getting mad If someone can help me then thank you very much!

Wiopsi daisies! Everything is fine now the first case was wrong. There should not be a second reverse. And the search should start from 8000, not 0 My bad

  (when not like column_name '% -%') then 0 occurs when the ('% -%' column_name) cast (SUBSTRING (reverse (column_name), LN (column_name) - (CHARINDEX ('-', column_name) -2), 8000) end),    

No comments:

Post a Comment