2 回答
TA贡献1853条经验 获得超9个赞
我找到了解决此问题的方法,我是这样做的(我将仅显示本机查询,因为它是我唯一更改的内容):
DECLARE @actNum varchar(50),@crdNum varchar(50),@pseId varchar(50),@dateMin varchar(50),@dateMax varchar(50),@amountMin varchar(50),@amountMax varchar(50)
SET @actNum = :actNum
SET @crdNum = :crdNum
SET @pseId = :pseId
SET @dateMin = :dateMin
SET @dateMax = :dateMax
SET @amountMin = :amountMin
SET @amountMax = :amountMax
--Whatever Select with joins statement
WHERE ACT.ACT_AccountNumber = CASE WHEN @actNum = 'N/A'
THEN ACT.ACT_AccountNumber
ELSE @actNum END
AND CRD_CardNumber = CASE WHEN @crdNum = 'N/A'
THEN CRD_CardNumber
ELSE @crdNum END
AND PSE.PSE_Id= CASE WHEN @pseId = 'N/A'
THEN PSE.PSE_Id
ELSE @pseId END
AND PSR.PSR_CreateDate >= CASE WHEN @dateMin = 'N/A'
THEN PSR.PSR_CreateDate
ELSE @dateMin END
AND PSR.PSR_CreateDate <= CASE WHEN @dateMax = 'N/A'
THEN PSR.PSR_CreateDate
ELSE @dateMax END
AND PSR.PSR_Amount BETWEEN CASE WHEN @amountMin = 'N/A'
THEN PSR.PSR_Amount
ELSE @amountMin END
AND CASE WHEN @amountMax = 'N/A'
THEN PSR.PSR_Amount
ELSE @amountMax END
ORDER BY PSR.PSR_CreateDate DESC
后端会将参数作为“N/A”(如果不应该用于过滤数据)或实际值发送,这对我来说很好用!
添加回答
举报