Link to home
Start Free TrialLog in
Avatar of Neil Woods
Neil Woods

asked on

Switch statements in access in SQL Server

Hi Im trying to transorm some access database, reports queries etc into SQL Server.

I'm having issues with some of the queries where they are group by and counts using switch statements in access

see below.....how would i mimic this in sql server?

SELECT tblStaff.Full_Name, tblCompany.Managed_Account_Agent, tblStaff.Manager, tblStaff.Email, Count(tblCompany.Managed_Account_Agent) AS [TOTAL MAs], Count(Switch([REMOVE_FROM_LEADCHECKING_PLATFORM] Is Null,[Managed_Account_Agent])) AS [TOTAL F2C MAs], Count(Switch([REMOVE_FROM_LEADCHECKING_PLATFORM] Is Null And [Actual_Number_Of_Employees]>1 And [Mobile_Provider]>"" And [PMOBHAND]>0 And [EXP_Date] Is Not Null,1)) AS [Mobile_Profile F2C], ([Mobile_Profile F2C]/[TOTAL F2C MAs]) AS [Mobile_Profile F2C %]
FROM tblCompany INNER JOIN tblStaff ON tblCompany.Managed_Account_Agent = tblStaff.SystemName
GROUP BY tblStaff.Full_Name, tblCompany.Managed_Account_Agent, tblStaff.Manager, tblStaff.Email
HAVING (((tblStaff.Manager)<>"leaver"));
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America 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
ASKER CERTIFIED 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
Recommend generally splitting points between Dale and Ste5an, as they both actually rewrote the SQL and made the changes appropriate to this query, while Scott provided more generalized solution.  Recommend awarding Dale a few extra points as he [I] recognized that the user should be using a WHERE clause rather then a HAVING clause, to speed up processing.