我有下面的代碼需要基於參數的條件條件。IS可以實現嗎?如何使用SQL對這種類型。我沒有看到任何varaiation的方法來做到這一點沒有在IN條件的where子句中使用CASE
BEGIN
DECLARE @INPUT AS VARCHAR(256)
set @input = 'NASS'
SELECT
sum(TRY_PARSE(DV.[ERSDataValues_AttributeValue1] as decimal)) AS NEWVALUE
FROM [VegetablesCoSD-Full].[CoSD].[ERSDataValues] DV LEFT JOIN [CoSD]. [ERSTimeDimension_LU] TD
ON DV.ERSDataValues_ERSTimeDimension_ID = TD.ERSTimeDimension_ID
WHERE DV.ERSDataValues_ERSStatisticType_ID1 = 45 AND
DV.ERSDataValues_ERSCommodity_ID = 519 AND
DV.ERSDataValues_ERSGeography_ID = 3346 AND
DV.ERSDataValues_ERSUnit_ID1 = 89 AND
TD.ERSTimeDimension_TimeDimensionType_ID = 11 and
CASE
when @INPUT = 'NASS' THEN
TD.ERSTimeDimension_Month in
('1','2','3','4','5','6','7','8','9','10','11','12')
WHEN @INPUT = 'BLS' THEN
TD.ERSTimeDimension_Month IN('JAN','FEB')
END
是否有任何錯誤◆當運行這個? – User2012384
不,它沒有任何錯誤... –