Bineesh  Viswanath

Bineesh Viswanath

  • NA
  • 1k
  • 777.3k

How to search db value with 'or' condition sql server

Sep 16 2017 4:53 AM
Hi Sir,
 
I am in a project in which I need to implement search criteria using OR condition.
 
means, I need to search different column values based upon one sql parameter.
 
Kindly tell me the below query to replace 'AND' condition with 'OR'
 
isnull(cast(tblCustomer.strMobile as nvarchar (20)),'') LIKE '%'+@asMobile+'%'
and
 
isnull(cast(tblCustomer.strPhoneOff as nvarchar (20)),'') LIKE '%'+@asMobile+'%' and
isnull(cast(tblCustomer.strPhoneOff1 as nvarchar (20)),'') LIKE '%'+@asMobile+'%' and
isnull(cast(tblCustomer.strPhoneRes as nvarchar (20)),'') LIKE '%'+@asMobile+'%'
for c# code , I given like this:-
 
cmd.Parameters.Add("@asstrMobile", SqlDbType.NVarChar).Value = tbxOfficeResMobile.Text.Trim();
cmd.Parameters.Add("@asPhoneOff", SqlDbType.NVarChar).Value = tbxOfficeResMobile.Text.Trim();
cmd.Parameters.Add("@asPhoneOff1", SqlDbType.NVarChar).Value = tbxOfficeResMobile.Text.Trim();
cmd.Parameters.Add("@asPhoneRes", SqlDbType.NVarChar).Value = tbxOfficeResMobile.Text.Trim();
 
This code is not working because of all parameter taking same value. I think I need to change the SQL

Answers (7)