I was wondering what were the best practices for making a query in sql with a dynamic value, lets say i have a Value(nvarchar(max))
value: "912345678"
select * from AllData
where Number like '%912345678%'
value: "Michael"
select * from AllData
where Name like '%Michael%'
value: "Street number 10"
select * from AllData
where Address like '%Street number 10%'
This approuches are a bit slow since searching for a number that has 9 digits would be faster without % like this
select * from AllData
where Number like '912345678'
I use a EDMX to make a connection to an external database in C#, like this:
var Result = EDMXEntity.Entities.Where(x =>
(SqlFunctions.PatIndex("%" + Value.ToLower() +"%", x.Name.ToString().ToLower()) > 0)
|| (SqlFunctions.PatIndex("%" + Value.ToLower() +"%", x.Number.ToString().ToLower()) > 0)
|| (SqlFunctions.PatIndex("%" + Value.ToLower() +"%", x.Address.ToString().ToLower()) > 0)).Take(50).ToList();
How can i increase performance?