Link to home
Start Free TrialLog in
Avatar of bkpierce
bkpierceFlag for United States of America

asked on

SQL Reporting IIF help

I have a report in crystal that I'm trying to duplicate in SQL reporting. It displays various information about projects. One of the fields in the report is Expected Contract, depending on what contract type is this information can be found in 3 differnt fields.

The contract field type is JC00102.Contract_Type, it can have a value of 1,2, or 3.

The dollar amount is in the corresponding fields based on contract type

If contract_type =1 dollar amount is in JC00102.Expected_Contract
If contract_type =2 dollar amount is in JC00107.User_Defined_Dollar_1
If contract_type =3 dollar amount is in JC00102.Contract_Max_Bill_Amt

I have one table cell that I need to display the "Expected Contract" based on the information above. How can I do this in SQL Syntax? I'm pretty sure I need to use IIF but not 100% sure.
ASKER CERTIFIED SOLUTION
Avatar of Megan Brooks
Megan Brooks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Howard Cantrell
You can use a IIF, but you may want to try this in your Code expression edit area.....
In the code below you may need to change the type to whatever you are using coming from your SP.
If you want  to use the IIF you will need to nest them.
Let me know and I can get it to you.

Public Function ContractType(ByVal Contract as String) as String
Select Contract
     Case "1"
           Return JC00102.Expected_Contract
     Case "2"
          Return JC00107.User_Defined_Dollar_1
  Case "3"
       Return JC00102.Contract_Max_Bill_Amt
End Select
Return Nothing
End Function

Place this in your cell...
=Code.ContractType(Fields!contracttype.Value) 

Open in new window

In MS SQL use the following expression in your select statement:


SELECT CASE WHEN  JC00102.Contract_Type=1 THEN JC00102.Expected_Contract
                             WHEN  JC00102.Contract_Type=2 THEN  JC00107.User_Defined_Dollar_1
                             WHEN  JC00102.Contract_Type=3 THEN JC00102.Contract_Max_Bill_Amt
                 END


In Reporting services, use an IIF Statement similar to the following:
=IIF(Fields!contract_type.Value=1, Fields!Expected_Contract, IIF(Fields!contract_type.Value=2, Fields!User_Defined_Dollar_1, Fields!Contract_Max_Bill_Amt))
This assumes that contract_type.Value will always return 1,2 or 3.


Hope this helps


Rob
Avatar of bkpierce

ASKER

Using switch worked great, thanks for your hlep.