• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

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.
0
bkpierce
Asked:
bkpierce
1 Solution
 
Megan BrooksSQL Server ConsultantCommented:
If you are sure that the only types are 1, 2, and 3 then you could simply do
=Choose(Fields!contract_type.Value, Fields!Expected_Contract, Fields!User_Defined_Dollar_1, Fields!Contract_Max_Bill_Amt)
For better error handling, if other types could be present, you could use Switch() instead and include a default case at the end.
I don't know exactly what your field names are, so I just made these up based on the table information.
0
 
planoczCommented:
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

0
 
shorakCommented:
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
0
 
bkpierceAuthor Commented:
Using switch worked great, thanks for your hlep.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now