Print Page | Close Window

probelm using select case

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17495
Printed Date: 06 May 2024 at 1:03am


Topic: probelm using select case
Posted By: bwsanders
Subject: probelm using select case
Date Posted: 05 Sep 2012 at 2:41am
when I run this report using the select case code below it tells me that every employee is of asian descent. Am I doing something wrong here?

Thank you in advance for your help!


//A    Asian
//B    African American
//F    Foreign National
//H    Hispanic
//I    Native American/Alaskan Native
//M    Middle Eastern
//O    Other
//P    Native Hawaiian or Pacific Islander
//T    Two or More Races
//Undefined    Undefined
//W    Caucasian

Select {CEthnicity.ethnicity}
    case "A"
    :"Asian"
    case "B"
    :"African American"
    case "F"
    :"Foreign National"
    case "H"
    :"Hispanic"
    case "I"
    :"Native American/Alaskan Native"
    case "M"
    :"Middle Eastern"
    case "O"
    :"Other"
    case "P"
    :"Native Hawaiian or Pacific Islander"
    case "T"
    :"Two or More Races"
    case "Undefined"
    :"Undefined"
    case "W"
    :"Caucasian"
    Default
    :"Undefined";




Replies:
Posted By: hilfy
Date Posted: 05 Sep 2012 at 3:55am
What error are you getting?  If you're not getting any data, try taking the semi-colon (;) off the end of it. 
Personally, I tend to use the Crystal Syntax "Switch" statement instead of select/case.  It would look something like this:
 
Switch(
  IsNull({CEthnicity.ethnicity}), 'Undefined',
  {CEthnicity.ethnicity} = 'A', 'Asian',
  {CEthnicity.ethnicity} = 'B', 'African American',
  ...
  {CEthnicity.ethnicity} = 'W', 'Caucasian,
  true, 'Undefined'}
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: bwsanders
Date Posted: 05 Sep 2012 at 4:08am
thank you for your quick reply. i tried removing the semi colon from the end of the code and still got the same result. i changed out the code completely and tried the "switch" statement and that is still giving me the same result.

it is returning data however it is telling me that every employee is Asian instead of going through the whole statement and showing their true ethnicity.

any thoughts? this is the current code from the report.

Switch(
  IsNull({CEthnicity.ethnicity}), 'Undefined',
    {CEthnicity.ethnicity} = 'A', 'Asian',
    {CEthnicity.ethnicity} = 'B', 'African American',
    {CEthnicity.ethnicity} = 'F', 'Foreign National',
    {CEthnicity.ethnicity} = 'H', 'Hispanic',
    {CEthnicity.ethnicity} = 'I', 'Native American/Alaskan Native',
    {CEthnicity.ethnicity} = 'M', 'Middle Eastern',
    {CEthnicity.ethnicity} = 'O', 'Other',
    {CEthnicity.ethnicity} = 'P', 'Native Hawaiian or Pacific Islander',
    {CEthnicity.ethnicity} = 'T', 'Two or More Races',
    {CEthnicity.ethnicity} = 'U', 'Undefined',
    {CEthnicity.ethnicity} = 'W', 'Caucasian',
  true, 'Undefined')


Posted By: hilfy
Date Posted: 05 Sep 2012 at 4:34am
I would put the  {CEthnicity.ethnicity} field on the report and see what data is being returned in it just to validate that the various values are there.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: bwsanders
Date Posted: 05 Sep 2012 at 4:47am
thank again dell, here is what i am getting returned when i just use {CEthnicity.ethnicity}

LastName  FirstName  Annual Salary  FT/PT

Heflin Catherine A F 




LastName  FirstName  Annual Salary  FT/PT

Hill Justin A M 




LastName  FirstName  Annual Salary  FT/PT

Hill Natasha A F 




LastName  FirstName  Annual Salary  FT/PT














The 'A' (Asian) is returning for every employee. so i'm assuming it's the actual database that is incorrect?  when i run this as a sql query it returns the correct data ie employees lastname, firstname and ethnicity.


Posted By: bwsanders
Date Posted: 05 Sep 2012 at 5:01am
i figured it out. i was actually calling the wrong table. we'll chalk this one up to a rookie mistake ;)

thank you for your help!

now i just need to figure out how to stop the header from repeating and line up the cells under it.



Print Page | Close Window