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"

Comments

Anonymous said…
Informative article, exactly what I needed.

Here is my web blog ... conservatory prices
Pancratius said…
You might as well use a Coalesce function in the stored procedure.
indu said…
hi nice post . exactly what I wa slooking for
Anonymous said…
nice post. Exactly what I was looking for

Popular posts from this blog

Load data from CSV into HIVE table using HUE browser

Gitlab change project visibility from private to internal

Setting property 'keystoreFile' did not find a matching property. No Certificate file specified or invalid file format