J
JB
Hello Community
I am passing parameters SQL Server from an C# ASP.NET app. When
creating the query I have need to use an “or†operator after the Where clause
when comparing values. Does anyone know the syntax for this type of thing?
Below is the code:
public DataSet getCustomer(string Addr, int PhoneNo)
{
string strSQL = " select distinct a.firstname + ' ' +
a.lastname as Name";
strSQL += " from table1 a Join Table2 b ";
strSQL += " on a.id = b.id ";
strSQL += " WHERE a.Addr = " + Addr;
strSQL += " AND (b.PhoneNo = + PhoneNo OR b.PhoneNo <>
PhoneNo);
strSQL += " order by a.lastname, a.firstname ";
}
If I only wanted to check whether the PhoneNo was equal the following code
works:
strSQL += " AND c.PhoneNo = " + PhoneNo;
But I want to get a result returned whether the PhoneNo is equal or the
PhoneNo is not
That means the question is:
When passing variable and comparing values what is the syntax for the “orâ€
operator within the Where clause and are the parenthesis necessary?
Thanks
Jeff
I am passing parameters SQL Server from an C# ASP.NET app. When
creating the query I have need to use an “or†operator after the Where clause
when comparing values. Does anyone know the syntax for this type of thing?
Below is the code:
public DataSet getCustomer(string Addr, int PhoneNo)
{
string strSQL = " select distinct a.firstname + ' ' +
a.lastname as Name";
strSQL += " from table1 a Join Table2 b ";
strSQL += " on a.id = b.id ";
strSQL += " WHERE a.Addr = " + Addr;
strSQL += " AND (b.PhoneNo = + PhoneNo OR b.PhoneNo <>
PhoneNo);
strSQL += " order by a.lastname, a.firstname ";
}
If I only wanted to check whether the PhoneNo was equal the following code
works:
strSQL += " AND c.PhoneNo = " + PhoneNo;
But I want to get a result returned whether the PhoneNo is equal or the
PhoneNo is not
That means the question is:
When passing variable and comparing values what is the syntax for the “orâ€
operator within the Where clause and are the parenthesis necessary?
Thanks
Jeff