Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hello,
I want to select values that start with some value and order by the number of space containing in the result.
I means...
If I want to find key word "go" and then,
results may be... "go after","go and leave","go", etc...
and I want to get result as
"go and leave", (having 3 spaces)
"go after, (having 2 spaces)
"go" (having 1 space)

How can I write my query from this,
SELECT * FROM [table1] WHERE [column1] LIKE 'go%' ORDER BY...?
If I can't retrieve data using order by command only, Is there any way to execute in sql only such as writing SQL function in stored procedure. Thanks alots.
Posted

Have a look at this question that looks like it'll do what you need

http://www.dotnetspider.com/forum/156982-How-count-blank-space-using-sqlserver.aspx[^]
 
Share this answer
 
Comments
whitehaker 6-Apr-11 7:47am    
Thanks..
try this

SQL
SELECT Name, LEN(Name)- LEN(REPLACE(Name ,' ','')) [CNT]
FROM test5 order by CNT desc
 
Share this answer
 
Comments
whitehaker 7-Apr-11 5:15am    
Thanks for your help.

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