[英]Report builder (SSRS) SWITCH statement blank values
For a report I'm building, there are fields that are dependent on a user selecting to add additional people to their policy (named in the dataset as dependent1, dependent2, etc).对于我正在构建的报告,有些字段取决于用户选择将其他人添加到他们的策略(在数据集中命名为dependent1、dependent2 等)。
We need to determine whether these dependants are adults or children for reporting.我们需要确定这些家属是成年人还是儿童进行报告。 This will be done via DOB and a DateDiff which I understand这将通过 DOB 和我理解的 DateDiff 完成
Currently, I can get the report to show ADULT
or CHILD
if data is present, however if there isn't any data I can't return a ""
value, it just defaults to ADULT
.目前,如果数据存在,我可以让报告显示ADULT
或CHILD
,但是如果没有任何数据,我无法返回""
值,它只是默认为ADULT
。
I'm using:我正在使用:
=Switch(DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) < 18, "CHILD",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) >= 18, "ADULT",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value), "")
I also created another column which uses the DateDiff between Fields!Dependant1DoB.Value & Fields!Policy_Start_Date.Value to show the number of years.我还创建了另一列,它使用 Fields!Dependant1DoB.Value & Fields!Policy_Start_Date.Value 之间的 DateDiff 来显示年数。 This works and returns a number.这有效并返回一个数字。 however for some unknown reason where there's no data it still returns "2019" which may be effecting it?但是,由于某些未知原因,在没有数据的情况下,它仍然返回“2019”,这可能会影响它? I've tried including this in the Switch statement ( DateDiff("yyyy",Fields!Dependant1DoB.Value,Fields!Policy_Start_Date.Value)=2019, "")
) but this still doesn't work.我已经尝试在 Switch 语句中包含它( DateDiff("yyyy",Fields!Dependant1DoB.Value,Fields!Policy_Start_Date.Value)=2019, "")
),但这仍然不起作用。
Someone please help as this is driving me loopy!有人请帮忙,因为这让我疯了!
You need to first check for nothing and then apply the switch function, example below:您需要先检查什么,然后应用开关功能,示例如下:
=IIF(IsNothing(Fields!Dependent1DoB.Value),"", Switch( DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)<18, "CHILD", DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)>=18, "ADULT" ) ) =IIF(IsNothing(Fields!Dependent1DoB.Value),"", Switch(DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)<18, "CHILD", DateDiff("yyyy",Fields! Dependent1DoB.Value,Fields!Policy_Start_Date.Value)>=18, "ADULT" ) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.