Archive for the ‘SQL Reporting Services’ Category

Using the SWITCH expression to change text colours in SQL Server Reporting Services

Tuesday, December 2nd, 2008

Using the SWITCH expression to change text colours in SQL Server Reporting Services
When you need to dynamically change the text colours for a report field/column you can make use of the SWITCH expression.  It comes in handy when you want to represent multiple values with different colours.  Unlike the IIF expression which essentially only gives you an either/or choice, SWITCH functions more like a CASE statement.
To implement the switch, select your data field in RS report designer, then select <Expression…> from the properties dialog:


Now supply the logic, for example:

=Switch( Fields!ows_State.Value ="Closed","black",
Fields!ows_State.Value="Overdue", "red",
Fields!ows_State.Value="Open", "green")

SWITCH consists of pairs of evaluation/result sets separated by commas.  If your field contains numbers values you can also use numeric comparison operators (>, < , >= etc.)