I have two tables: AreaCode
and EquipmentNumber
.
+------------------------------------+
| AreaCd |
|---
I think this is what you are after :
Just added a simple trick;
if(string.IsNullOrEmpty(sNumber))
sNumber="$$$"; //If sNumber is empty, then selection using sNumber= '$$$' will return nothing.
if(string.IsNullOrEmpty(sType))
sType="$$$" //If sType is empty, then selection using sType = '$$$' will return nothing.
"SELECT Number, Type, Code FROM EqNum, AreaCd " +
"WHERE EqNum.AreaId = AreaCd.AreaId
AND
(Code = " + int nCode + "
OR Number = '" + string sNumber + "'
OR Type = '" + string sType + "')"
OR using LIKE
:
if(string.IsNullOrEmpty(sNumber))
sNumber="$$$"; //If sNumber is empty, then selection using sNumber LIKE '%$$$%' will return nothing.
if(string.IsNullOrEmpty(sType))
sType="$$$" //If sType is empty, then selection using sType LIKE '%$$$%' will return nothing.
"SELECT Number, Type, Code FROM EqNum, AreaCd " +
"WHERE EqNum.AreaId = AreaCd.AreaId
AND
(Code = " + int nCode + "
OR Number LIKE '%" + string sNumber + "%'
OR Type LIKE '%" + string sType + "%')"
See an example at SQL Fiddle