I used nested immediate IFs and the Switch function. It's long!!
Here is the statement:
Code:
IIf([PerformanceType]="S",Switch([PerformanceResult]=0,"NA",[PerformanceResult]=1,1,[PerformanceResult]=2,2,[PerformanceResult]=3,3,[PerformanceResult]=4,4,[PerformanceResult]=5,5),IIf([PerformanceType]="R",Switch([PerformanceResult]=0,"Poor",[PerformanceResult]=1,"Fair",[PerformanceResult]=2,"Average",[PerformanceResult]=3,"Good",[PerformanceResult]=4,"Excellent"),IIf([PerformanceType]="Y",Switch([PerformanceResult]=0,"No",[PerformanceResult]=1,"Yes"),"ERROR")))
Here is the SQL for a query:
Code:
SELECT EvaluationAllInfo.PerformanceType, EvaluationAllInfo.PerformanceResult, IIf([PerformanceType]="S",Switch([PerformanceResult]=0,"NA",[PerformanceResult]=1,1,[PerformanceResult]=2,2,[PerformanceResult]=3,3,[PerformanceResult]=4,4,[PerformanceResult]=5,5),IIf([PerformanceType]="R",Switch([PerformanceResult]=0,"Poor",[PerformanceResult]=1,"Fair",[PerformanceResult]=2,"Average",[PerformanceResult]=3,"Good",[PerformanceResult]=4,"Excellent"),IIf([PerformanceType]="Y",Switch([PerformanceResult]=0,"No",[PerformanceResult]=1,"Yes"),"ERROR"))) AS xyz
FROM EvaluationAllInfo;
Another way would be to write a UDF to return the result.
Code:
Public Function GetResultText(pType As String, pResult As Long) As String
Select Case pType
Case "S"
Select Case pResult
Case 0
GetResultText = "N/A"
Case Else
GetResultText = pResult
End Select
Case "R"
Select Case pResult
Case 0
GetResultText = "Poor"
Case 1
GetResultText = "Fair"
Case 2
GetResultText = "Average"
Case 3
GetResultText = "Good"
Case 4
GetResultText = "Excellent"
Case Else
GetResultText = "Error"
End Select
Case "Y"
Select Case pResult
Case 0
GetResultText = "No"
Case 1
GetResultText = "Yes"
End Select
Case Else
GetResultText = "Error"
End Select
End Function
Code:
SELECT EvaluationAllInfo.PerformanceType, EvaluationAllInfo.PerformanceResult, GetResultText([PerformanceType],[PerformanceResult]) AS xyz
FROM EvaluationAllInfo;
In both queries, change "xyz" to whatever name you want...