Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Services / Reporting Services / July 2008

Tip: Looking for answers? Try searching our database.

Switch vs case

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian - 08 Jul 2008 02:35 GMT
Hi, I am trying to use a switch statement in reporting services because from
what I read RS doesn't do case and switch is supposed to be the equivalent. I
have found some examples but none seem to have the "else" equivalent in them.
Does switch have an else? What is the syntax

I'd like to do this

Case colour when red then "The colour is red"
                 when Blue then "The colour is Blue"
else "the colour isn't blue or red"
end

Thanks
Steve MunLeeuw - 08 Jul 2008 14:24 GMT
It doesn't directly, but you can accomplish the same thing with the last
condition always resolving to true.

=Switch(Fields!myColor.Value = "Red", "the spot is red",
Fields!myColor.Value = "Blue", "the spot is blue", 1 = 1, "some other
color")
I found the following in the help:

Evaluates a list of expressions, and returns the value associated with the
first condition that returns TRUE. Switch can have one or more
condition/value pairs.

Syntax
Switch(condition1, value1, .)

     condition1
    Indicates the condition to test.

     value1
    Specifies the value or expression that the item should be replaced
with, if the condition is True.

Example
     Formula  Result
     SWITCH(Customer Type = "I", "Individual", Customer Type = "S", "Shop

a.. The following expression also returns one of three values based on the
value of PctComplete, but uses the Switch function instead, which returns
the value associated with the first expression in a series that evaluates to
true:

Copy Code
=Switch(Fields!PctComplete.Value >= .8, "Green", Fields!PctComplete.Value >=
.5, "Amber", Fields!PctComplete.Value < .5, "Red")Thanks,
Steve MunLeeuw
Brian - 09 Jul 2008 01:31 GMT
Thats great thanks!
I'm struggling wit RS help

> It doesn't directly, but you can accomplish the same thing with the last
> condition always resolving to true.
[quoted text clipped - 31 lines]
> ..5, "Amber", Fields!PctComplete.Value < .5, "Red")Thanks,
> Steve MunLeeuw
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.