Link to home
Start Free TrialLog in
Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

if condition

please code below, i need to use code below less if statements, is look not properway or not very professional to use this much If conditions, i belive may be another way .

            if (ComplainType == "Total")
            {


                SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyTots";
            }


            if (ComplainType == "ManualKit")
            {


                SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyMan
            }


            if (ComplainType == "iComplaints")
            {


                SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyIcom
            }


            if (ComplainType == "InsComplaints")
            {


                SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyINS
            }
ASKER CERTIFIED SOLUTION
Avatar of Haris Dulic
Haris Dulic
Flag of Austria 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
SOLUTION
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
You should use a case statement for faster execution-

// ... Switch on the string.
	switch (ComplainType)
	{
	    case "Total":
                SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyTots";
		break;
	    case "ManualKit":
		  SqlTotalComplaints = "select count(*) as YearlyTotalComplaint from NumberOfComplaints_YearlyMan";
		break;
	    case "etc":
		etc;
		break;
	}

Open in new window

SOLUTION
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