t-sqlreporting-servicesc-stringsiif-function

SSRS nested IIF/CStr explanation


Could someone let me know if the IIF statement below means output any value that starts with a 4 please?

=IIF(LEFT(CStr(Fields!CLOCK_NUMBER.Value),1)="4",Fields!JOB_NO.Value, "")


Solution

  • The short answer is yes.

    Starting from the middle and working outwards this expression is doing the following..

    1. Get the value of the field CLOCK_NUMBER
    2. Convert this to a string (the CSTR function)
    3. Take the 1st character (LEFT function with 1 as the seconds parameter)
    4. If the equals "4" return the Value that is in JOB_NO
    5. Otherwise return an empty string

    If this is not working for some reason, try converting the job_no to a string before returning, that way you ensure you always return a string (in case JOB_NO is numeric). You can simply wrap the job_no in a CSTR like this CSTR(Fields!JOB_NO.Value)