简体   繁体   中英

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).

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

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 .

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. 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? 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.

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" ) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM