SSRS Switch statement with Not IsNothing condition
Sometimes it is required that you have display one of the available contact numbers such as either home phone or work phone or cell phone. I came across this requirement for one of our SSRS reports where we have to display the table of customers with one of their contact numbers. Here is the expression i used:
Switch
(
Not(IsNothing(Fields!home_phone.Value)),Fields!home_phone.Value,
Not(IsNothing(Fields!work_phone.Value)),Fields!work_phone.Value,
Not(IsNothing(Fields!cell_phone.Value)),Fields!cell_phone.Value,
1=1,"No # Listed"
)
It works like a charm.
How it works:
The Switch statement will first check if home phone is present. If its not null then select home phone. else it will check for work phone. If work phone is not null then select it else check for cell phone, so on and so forth. The last condition is "1=1" meaning it is always true. So in case if none of the numbers are available, then select this value "No # Listed"
Switch
(
Not(IsNothing(Fields!home_phone.Value)),Fields!home_phone.Value,
Not(IsNothing(Fields!work_phone.Value)),Fields!work_phone.Value,
Not(IsNothing(Fields!cell_phone.Value)),Fields!cell_phone.Value,
1=1,"No # Listed"
)
It works like a charm.
How it works:
The Switch statement will first check if home phone is present. If its not null then select home phone. else it will check for work phone. If work phone is not null then select it else check for cell phone, so on and so forth. The last condition is "1=1" meaning it is always true. So in case if none of the numbers are available, then select this value "No # Listed"
Comments
Here is my web blog ... conservatory prices