I currently have a query that does a distinct, so I can order the values on the screen.
select distinct CONVERT(real, RTRIM(REPLACE(Height, 'mm', ''))), Height from TEST_DATA where series = 'ABC' ORDER BY CONVERT(real, RTRIM(REPLACE(Height, 'mm', ''))) ASC
It works fine, but problem now... I don't have all numeric values in the 'xxmm' format in my Height records.
Now I have 2 records with 'Edge' in the record. So, I need to find a new way to order the above query with these new records.
Microsoft SQL Server
Last Comment
ee_rlee
8/22/2022 - Mon
ee_rlee
hi, try this
This should return records with Height='Edge' as the 1st record, then sort asc.
select distinct CONVERT(real, RTRIM(REPLACE(Height, 'mm', ''))), Height from TEST_DATA where series = 'ABC' ORDER BY CASE WHEN Height<>'Edge' THEN CONVERT(real, RTRIM(REPLACE(Height, 'mm', ''))) END ASC
select CASE WHEN Height='Edge' THEN 'Edge' ELSE RTRIM(REPLACE(Height, 'mm', '')) END, Height from TEST_DATA where series = 'ABC' group by HeightORDER BY CASE WHEN Height='Edge' THEN 0 ELSE CONVERT(real, RTRIM(REPLACE(Height, 'mm', ''))) END ASC
This should return records with Height='Edge' as the 1st record, then sort asc.
Open in new window