I need help for complex data sort from database. Suppose my data stored in table like this:
Description
--------------
JCB Excavator - ECU P/N: 728/35700
Geo Pri
Here you go
declare @t table(Description varchar(1000))
insert into @t
select 'JCB Excavator - ECU P/N: 728/35700 ' union all
select 'Geo Prism 1995 GEO - ABS #16213899 GEO pump ' union all
select 'Geo Prism 1995 - GEO ABS #16213897 ' union all
select 'Geo Prism 1995 - ABS #16213897 ' union all
select 'Ersatz Airbags, Gurtstrammer und Auto Körper Teile ' union all
select 'this test JCB pipe & JCB pump ' union all
select 'Wie man BBA reman erreicht'
declare @search_term varchar(100)
set @search_term ='GEO'
select Description from @t
order by len(Description)-len(replace(Description,@search_term,'')) desc
Result
Description
----------------------------------------------------------
Geo Prism 1995 GEO - ABS #16213899 GEO pump
Geo Prism 1995 - GEO ABS #16213897
Geo Prism 1995 - ABS #16213897
Ersatz Airbags, Gurtstrammer und Auto Körper Teile
this test JCB pipe & JCB pump
Wie man BBA reman erreicht
JCB Excavator - ECU P/N: 728/35700