Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to fetch data from data base which contains a particular word.Am using below query to fetch values
(UPPER(columnname) LIKE UPPER('%test%')
so this query is working fine and returning values.
Above query returning values like below order

aatest
ggtest
ddtest
test
kktest
mtest


but i want test as the first row,like below

test
aatest
ggtest
ddtest
kktest
mtest


test should come first as its matching with search word perfectly.But other values are also need to show but after test.

In c# side am showing this result in grid. I need to do this order in either in C# datatable or in oracle DB query.

Please help
Posted
Updated 12-Nov-14 0:35am
v4
Comments
Thava Rajan 12-Nov-14 2:49am    
what you mean by ordering, there is no order in your data
test
mtest
aatest
ddtest
ggtest
kktest
is this what you want?
Am Gayathri 12-Nov-14 3:04am    
'Test' should come first.Am not worried about the order of other items.

Add something like this at the end of query:
SQL
ORDER BY CASE WHEN FieldName = 'test' then 0 Else 1 END, FieldName


[EDIT]
Example: http://sqlfiddle.com/#!6/ca7a1/2[^]
 
Share this answer
 
v2
Comments
Am Gayathri 12-Nov-14 4:58am    
Its not working
Maciej Los 12-Nov-14 5:09am    
Working as well!
SqlFiddle[^]
Am Gayathri 12-Nov-14 6:27am    
Worked
Thanks
Maciej Los 12-Nov-14 6:54am    
You're welcome ;)
Apply the order by clause by replacing the Test word with blank

e.g. Order by Replace(columnname,'test','')
 
Share this answer
 
Comments
Am Gayathri 12-Nov-14 4:58am    
Its not working
Shweta N Mishra 12-Nov-14 5:07am    
It works and worked with below example

Create table #temp(col1 Varchar(10))
insert #temp select 'aatest'
insert #temp select 'ggtest'
insert #temp select 'ddtest'
insert #temp select 'test'
insert #temp select 'kktest'
insert #temp select 'mtest'

select * from #temp order by Replace(col1,'test','')
Shweta N Mishra 12-Nov-14 5:04am    
what is your command you ran, post your query here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900