Consider a column that contains a journey of at least one city pair and may look as follows JFK/BOS BOS/SLC SLC/LAX. Another column contains the number of stops (in this case 2).
The following expression will correctly report "BOS SLC". However in case the column contains JFK/BOS BOS/SLC or even only a non-stop JFK/BOS (stop values 1 and 0), the report will show "#error".
=Switch (
Fields!Stops.Value = 0, "",
Fields!Stops.Value = 1, Fields!ScheduleJourneyCityPairs.Value.Substring(4, 3),
Fields!Stops.Value = 2, Fields!ScheduleJourneyCityPairs.Value.Substring(4, 3) & " " &
Fields!ScheduleJourneyCityPairs.Value.Substring(12, 3),
Fields!Stops.Value = 3, Fields!ScheduleJourneyCityPairs.Value.Substring(4, 3) & " " &
Fields!ScheduleJourneyCityPairs.Value.Substring(12, 3) & " " &
Fields!ScheduleJourneyCityPairs.Value.Substring(20, 3)
)
This is due to the fact that SRS evaluates the complete expression, and errors on the fact that the column value is too short for offset 20. We can solve this by changing the last SELECT statement as follows:
SELECT
ScheduleJourney_RoutingID,
CASE WHEN LEN(ScheduleJourneyCityPairs) < 24
THEN ScheduleJourneyCityPairs + SPACE(24-LEN(ScheduleJourneyCityPairs))
ELSE ScheduleJourneyCityPairs
END AS ScheduleJourneyCityPairs,
JourneyDepartureStation,
....