Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JoJoDan
Starting Member
3 Posts |
Posted - 2010-02-11 : 11:24:41
|
Hi,I am working on a search on Member ScreenNames and the query below does what I need with one exception, I would like the results to start with the actual search phrase and then list the results that contain the search phrase in them.So for this: dbo.Search_SearchMembers 'br'The result currently are this:aBreezsseyBrianBrobZdBrdtsThe Results I would like are this:BrianBrobaBreezsseyZdBrdtsHow do I do that? I would appreciate any help I could get because I am stumped. Here is my Original Query:Alter Procedure dbo.Search_SearchMembers @SearchTerm varchar(255)AsSet NoCount On Set @SearchTerm = '%' + @SearchTerm + '%'; With OrderedResults As ( Select Row_Number() Over(Order By displayname) As 'Row', * From dbo.members Where isguest = 0 And confirmemail = 1 And displayname like @SearchTerm ) Select * From OrderedResults |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-11 : 11:29:03
|
| [code]order by case when yourstringcolumn LIKE @SearchTerm + '%' THEN 1 ELSE 0 END DESC,yourstringcolumn[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
JoJoDan
Starting Member
3 Posts |
Posted - 2010-02-11 : 12:16:33
|
Awesome thank you! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-11 : 12:19:25
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|