我正在从.NET
应用程序传递临时查询到Pervasive v11 PSQL,我相信我无法在存储过程和视图之外声明变量。由于我没有创建存储过程和视图的选项,如何在NULL
时从where子句中排除参数。如果我没有传递单个参数,那么我就不会从.net执行查询。
我采取的参数是
FirstName,LastName,DOB,Address,PersonID,OLnumber,PartSerialNumber
如果任何参数作为NULL
传递,我希望查询省略该特定OR
子句。
Select FirstName,LastName,CaseNumer,DOB,Address from
MasterTable mv LEFT JOIN
AdditionalTable at ON mv.PersonID = at.PersonID
LEFT JOIN Parts p ON mv.PersonID = p.PersonID
WHERE mv.OLNumber = '{ONumber}' OR at.OLNumber= '{ONumer}'
OR (CONCAT(rtrim(mv.FirstName), rtrim(mv.LastName)) = replace(ltrim('{Name}'), ' ', ''))
OR (CONCAT(rtrim(at.FirstName), rtrim(at.LastName)) = replace(ltrim('{Name}'), ' ', ''))
OR p.PartSerialNumber = '{PartSerialNumber}'
OR mv.PersonID = '{PersonID}' OR at.PersonID = '{PersonID}'
OR mv.Address = '{Address}' or at.PersonID = '{PersonID}'
OR mv.DOB = '{DOB}' or at.DOB = '{DOB}'