I have a string for e.g." Wills Smith & family, Practitioner "
I want to search keywords against a 'Company' table to determine whether the string suggests a company name or its just a persons name..
I have a table in database named as 'Company' with a single column 'Name' .
The values would be 'family','Sons','Inc.' etc . So if any of the word in the string above matches this column I should return true. Like in this case 'family' matches.
I want to break above string in store procedure as array and loop through the table to find if any of the word in the string matches in table. As soon as I get one match I want to exit . So I want to query backwards in the string as mostly company names are last word like 'inc' etc .
I am looking for good approach to solve this. I am using visual studio and sqlserver (store proc)
Loading
Pankaj PandeyPosted May 7, 2013, 1:08 AM
string [] x= name.split by space and create your query by looping it..
ex--- "select * fromn abc where xyz like'%"+x[0].tostring()+"%'"+" or xyz like'"+x[1].tostring()+"'";
try it, if still have some issue then write your code and explain in steps what the result you need, i'll complete it and send you.
thanks
fancyPosted May 7, 2013, 6:52 PM
VulpesPosted May 7, 2013, 5:35 PM
fancyPosted May 7, 2013, 4:58 PM
string[] split = input.Split();
//build query with
LIKE AND OR operators based on name field.
for (int i = 0; i < split.Length; i++)
{
if (i == 0)
{ nam = "NAME = '" + split[i].ToString()+ "'"; }
else if (i !=0)
{nam += " OR NAME = '" + split[i].ToString() + "'";}
}