Using case when in Cognos data item

痴心易碎 提交于 2019-12-13 06:35:09

问题


I have put this in the Data Filter expression and it causes error when running the report. What I'm trying to achieve here is that when the Force Expired column has a value of Force then the action on the two other columns such as ([Policy Expiration Date] and [Policy Effective Date] should use the logic used against the current_date.

case when [Force Expired] = 'Inforce' then ([Policy Expiration Date] >= current_date and [Policy Effective Date] <= current_date) else end

回答1:


Cognos is finicky about the exact syntax of conditionals in filters. I generally avoid CASE statements in filters for this reason. You can convert your filter to one of these two syntaxes instead:

IF ([Force Expired] = 'Inforce')
THEN ([Policy Expiration Date] >= current_date and [Policy Effective Date] <= current_date) 
ELSE (1=1)

([Force Expired] = 'Inforce' AND [Policy Expiration Date] >= current_date AND [Policy Effective Date] <= current_date) 
OR 
[Force Expired] <> 'Inforce'

If you insist on using a CASE statement then I believe you can put parentheses around your WHEN clause and provide a result for ELSE and it should work:

CASE 
WHEN ([Force Expired] = 'Inforce') 
THEN ([Policy Expiration Date] >= current_date AND [Policy Effective Date] <= current_date) 
ELSE (1=1) 
END

For some reason, Cognos insists on an ELSE clause.




回答2:


when you use case you have to specify what to do when the requirement is met - not to give another condition. something like: case when [bla] = "foo" then "return_value" else "nothing" end remember -whatever you write in a calculated vlue in a data item is translated to sql, and that's precisely how it also goes in sql...



来源:https://stackoverflow.com/questions/29355059/using-case-when-in-cognos-data-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!