locked
Convert a SQL statement to a SRSS statement RRS feed

  • Question

  • Hi ,

    Can anyone let me know how can I convert the below SQL statement into a SRSS expression . I am using SRSS 2008

    SQL Exression  :(CASE  WHEN 1 THEN [Ytd] - [Target] ELSE [Target] - Ytd  END)

    I want to convert the above statement in to a SRSS expression .Pls help.

    thnx

    Wednesday, April 23, 2014 4:50 PM

Answers

  • Hi pepcoder,

    Just as Naomi said, we can use IIF function or Switch function to achieve your requirement. For example, you are using the following T-SQL query:
    CASE  WHEN [Ytd] >1 THEN [Ytd] - [Target] ELSE [Target] - [Ytd]  END

    Then we can use the expression below to achieve the same goal in Reporting Services:
    =iif(Fields!Ytd.Value>1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)
    Or
    =Switch(Fields!Ytd.Value>1, Fields!Ytd.Value- Fields!Target.Value, Fields!Ytd.Value<=1, Fields!Target.Value- Fields!Ytd.Value)

    The following article contains IIF function and Switch function is for your reference:
    http://msdn.microsoft.com/en-us/library/ms157328.aspx

    If there are any other questions, please feel free to ask.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    • Proposed as answer by eralper Friday, April 25, 2014 8:36 AM
    • Marked as answer by pepcoder Sunday, April 27, 2014 4:57 AM
    Friday, April 25, 2014 8:00 AM
  • Hi pepcoder,

    To achieve the requirement, we can refer to the following expression:
    =iif(iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)=0,nothing,iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value))

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    • Marked as answer by pepcoder Monday, April 28, 2014 11:51 AM
    Monday, April 28, 2014 1:29 AM

All replies

  • Check IIF function in SSRS.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    • Proposed as answer by susheel1347 Thursday, April 24, 2014 8:36 PM
    Wednesday, April 23, 2014 4:55 PM
  • Hi pepcoder,

    Just as Naomi said, we can use IIF function or Switch function to achieve your requirement. For example, you are using the following T-SQL query:
    CASE  WHEN [Ytd] >1 THEN [Ytd] - [Target] ELSE [Target] - [Ytd]  END

    Then we can use the expression below to achieve the same goal in Reporting Services:
    =iif(Fields!Ytd.Value>1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)
    Or
    =Switch(Fields!Ytd.Value>1, Fields!Ytd.Value- Fields!Target.Value, Fields!Ytd.Value<=1, Fields!Target.Value- Fields!Ytd.Value)

    The following article contains IIF function and Switch function is for your reference:
    http://msdn.microsoft.com/en-us/library/ms157328.aspx

    If there are any other questions, please feel free to ask.

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    • Proposed as answer by eralper Friday, April 25, 2014 8:36 AM
    • Marked as answer by pepcoder Sunday, April 27, 2014 4:57 AM
    Friday, April 25, 2014 8:00 AM
  • The posted CASE expression doesnt make any sense. I think its missing the condition to check

    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    Friday, April 25, 2014 8:16 AM
  • Thanks Katherine. Expression mentioned got worked.However, I have a small query. What if the below expression returns 0 then I don't want to show any value in the report.How can I change the expression.

    ie: =iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)

    If the above expression returns a value of 0 then no need to show any values in the report. Column can be empty 

    Sunday, April 27, 2014 4:59 AM
  • Visakh.

    Your link is not opening. "Sorry, the page you were looking for in this blog does not exist."

     I have a small query. What if the below expression returns 0 then I don't want to show any value in the report.How can I change the expression.

    ie: =iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)

    If the above expression returns a value of 0 then no need to show any values in the report. Column can be empty 

    Sunday, April 27, 2014 5:57 AM
  • Hi pepcoder,

    To achieve the requirement, we can refer to the following expression:
    =iif(iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value)=0,nothing,iif(Fields!Ytd.Value >1, Fields!Ytd.Value- Fields!Target.Value, Fields!Target.Value- Fields!Ytd.Value))

    Thanks,
    Katherine Xiong


    Katherine Xiong
    TechNet Community Support

    • Marked as answer by pepcoder Monday, April 28, 2014 11:51 AM
    Monday, April 28, 2014 1:29 AM