Case Statement and Nested IIFs

  • I have a large amount of textboxes which will look at the results of another textbox and depending on the results will give alternative answers...i.e present expression:

    =IIF(reportitems!txtbox1.value = "NA", " ", IIF(reportitems!txtbox1.value < .75, 1, IIF(reportitems!txtbox1.value < .85, 2, IIF(reportitems!txtbox1.value < .95, 3, 4))))[/i] when I run the report I get a #error result. If I put in the just the first arguement involving the "NA" - I recieve a valid answer, if I put in the 2nd arguement nested... I get the error again. :w00t: I have a feeling i need to create a CASE STATEMENT but I can't find where to put the CASE - In Custom Code or in the Behind Code. Examples would be wonderful if anyone is willing to share... or if anyone can help with my nested IIF issue. Thanks 🙂

  • I had to do something similar. I was building a dynamic URL based on the data populated within another textbox in the table. I tried the IIF statements and it just wouldn't work (mainly because I had NULL values in some of the records). So, I ended up looking up a VB.Net code example on Google and build a customer code function. It allowed me to pass in the values I was checking and then use a CASE statement to then build the URL I needed and then return the URL value back to the textbox in an expression under the Action settings for the textbox.

    Not sure if this will help, but it should give you at least some idea of the structure to use:

    Function GetQuoteLink (ResType As String, InTAId As Nullable (Of GuID),InTRId As Nullable (Of GuID),InGQId As Nullable (Of GuID)) As String

    Dim link as String

    Dim outid As String

    Select Case ResType

    Case "TA"

    outid = InTAId.ToString()

    link = "Globals!ReportServerUrl.ToString() &" & Chr(34) & "?/Everest/" & "ZZZ/" & "QuoteContentList&rs:Command=Render&rc:Parameters=false&QuoteToContent=" + outid

    Case "TR"

    outid = InTRId.ToString()

    link = "Globals!ReportServerUrl.ToString() &" & Chr(34) & "?/Everest/RZZZ/RetroQuoteContentList&rs:Command=Render&rc:Parameters=false&RetroQuoteToContent=" + outid

    Case "GQ"

    outid = InGQId.ToString()

    link = "Globals!ReportServerUrl.ToString() &" & Chr(34) & "?/Everest/GZZZ/GroupQuoteSummary&rs:Command=Render&rc:Parameters=false&GroupQuoteId=" + outid

    End Select

    Return link

    End Function

  • Thanks for the quick response.

    I'm still a little wet behind the ears on the code writing to a certain degree... Couple of questions

    Where do I write this code - does it go into Custom Code or the behind the report Code, if so, does it go under Body>ReportItems??

    I looked at the code you gave and don't quite see where you reference the relevant textboxes... I get the idea but like I said things are little fuzzy still for me.

    Thanks

    again. 😀

  • Thats ok. We all learn through doing and asking a lot of questions.

    As far as I know, the only place to enter custom code is on the report properties. The editor kind of stinks. I'm green too when it comes to the code. But, try searching google for vb case statement and function examples.

    When you call the custom code, you'll use the following (I'll use my example from the earlier post):

    For my example, I wanted the user to be able to click on the value in the textbox and link to a detail report for that specific item. So, in the textbox properties, I selected Action, then in the textbox for the URL expression on the Action panel, I entered the following as the expression:

    =Code.GetQuoteLink(Fields!ResultType.Value, Fields!TA_QuoteId.Value, Fields!RetroQuoteId.Value,Fields!RecID.Value)

    Basically, anytime you want to refer to a piece of custom code, you do so through an expression starting with =Code.name of function

    I hope that makes sense. One thing that I found as a HUGE help (and its not a plug) I bought the book Applied Microsoft SQL Server 2008 Reporting Services. The author does a very good job of explaining things in a fair amount of detail.

    Good luck.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply