Suppose I have 3 records, named 'PROBLEM', 'BIG PROBLEM', and 'VERY BIG PROBLEM' in the column Name
and I want to filter in the stored procedure
. My SP can take one parameter, that is @p
and I want find records on the basis of that parameter. I am stuck in the condition where I should find 'VERY BIG PROBLEM' if I get parameter either
- VE (As 'VERY' starts with 'VE')
- BI (As 'BIG' starts with 'BI')
- PRO (As PROBLEM start with 'PRO')
One solution could be using Where name like '%' + @p + '%'
, but it can give undesired results like if I search for 'Phil' and give parameter as 'Ph' then result will be 'Phil' and 'Joseph' as both has 'Ph' keyword. Is there any solution? As I am using ADO.Net
, C#
solution also be appreciated.
My Goal
If I search 'VE' then 'VERY BIG PROBLEM' should come as a result if I use name like @p + '%'
, but the same result should come on 'VE', 'BI' and 'PRO' also. Its like splitting the value on the white space and matching the result which each word.
I can give C# example:
string name = 'VERY BIG PROBLEM';
string[] terms = name.Split(' ');
Note the term
array contains 3 values; that is 'VERY', 'BIG', and 'PROBLEM'.
So if I search for either 'VE', 'BI', or 'PRO' it should give me the same result. If it's still unclear, suppose a scenario where we want to search for the name of a cricketer 'Abraham Benjamin Devilliers'. Let my parameter be 'Abrah', 'Benj' or 'Dev'; it should search 'Abraham Benjamin Devilliers' for me.