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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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...

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

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

bkpierceAuthor Commented:
Using switch worked great, thanks for your hlep.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.