want to get same output by SQL/TSQL what i am getting by the LINQ query

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
using LINQ i am query a data for sorting and i am getting right answer.<br/>
<br/>
here is my data & linq query......please have look.<br/>
<br/>
void Main()<br/>
{<br/>
List<SearchResult> list = new List<SearchResult>() {<br/>
new SearchResult(){ID=1,Title="Geo Prism GEO 1995 GEO* - ABS #16213899"},<br/>
new SearchResult(){ID=2,Title="Excavator JCB - ECU P/N: 728/35700"},<br/>
new SearchResult(){ID=3,Title="Geo Prism GEO 1995 - ABS #16213899"},<br/>
new SearchResult(){ID=4,Title="JCB Excavator JCB- ECU P/N: 728/35700"},<br/>
new SearchResult(){ID=5,Title="Geo Prism GEO,GEO 1995 - ABS #16213899 GEO"},<br/>
new SearchResult(){ID=6,Title="dog"},<br/>
};<br/>
<br/>
var to_search = new[] { "Geo", "JCB" }.Select(x => x.ToLower()).ToArray();<br/>
<br/>
var result = from searchResult in list<br/>

let title = searchResult.Title.ToLower()<br/>

let key_string = to_search.FirstOrDefault(ts => title.Contains(ts))<br/>

orderby key_string == null ? -1 : title.Split(new[] { key_string }, StringSplitOptions.None).Length descending<br/>

group searchResult by key_string into Group<br/>

orderby Group.Count() descending<br/>

select Group;<br/>

<br/>

result.Dump();<br/>

<br/>
}<br/>
<br/>
public class SearchResult<br/>
{<br/>
public int ID { get; set; }<br/>
public string Title { get; set; }<br/>
}<br/>
// Define other methods and classes here<br/>
<img alt="" src="http://i.stack.imgur.com/SBoR9.png <br/>
my question is what sql query i need to write as a result i will get same output in sql server 2000. suppose my data is stored in sql server table like this way<br/>
<br/>
Table : MyTable<br/>
------------------<br/>
ID Title<br/>
-----------<br/>
1 Geo Prism GEO 1995 GEO* - ABS #16213899<br/>
2 Excavator JCB - ECU P/N: 728/35700<br/>
3 Geo Prism GEO 1995 - ABS #16213899<br/>
4 JCB Excavator JCB- ECU P/N: 728/35700<br/>
5 Geo Prism GEO,GEO 1995 - ABS #16213899 GEO<br/>
6 Maruti gear box #ABS 4587<br/>

View the full article
 
Back
Top