我试图根据存储过程的输入变量在sql中设置我的where条件。
Where RF.InternalCompany = @Company
And RF.Installdate between @Datefrom and @DateTo
AND CASE WHEN @ContractType = 'Single Asset Contract' THEN numA.NumOfAssets = 1
WHEN @ContractType = 'Multi-Asset Contract' THEN numA.NumOfAssets > 1
END
如何设置?
答案 0 :(得分:2)
如下所示进行更改..
Where RF.InternalCompany = @Company
And RF.Installdate between @Datefrom and @DateTo
AND ((@ContractType = 'Single Asset Contract' AND numA.NumOfAssets = 1 ) Or
(@ContractType = 'Multi-Asset Contract' AND numA.NumOfAssets > 1))
答案 1 :(得分:1)
AND
(
( @ContractType = 'Single Asset Contract' AND numA.NumOfAssets = 1 )
OR
( @ContractType = 'Multi-Asset Contract' AND numA.NumOfAssets > 1 )
)