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_A ccount_Age nt) AS [TOTAL MAs], Count(Switch([REMOVE_FROM_ LEADCHECKI NG_PLATFOR M] Is Null,[Managed_Account_Agen t])) AS [TOTAL F2C MAs], Count(Switch([REMOVE_FROM_ LEADCHECKI NG_PLATFOR M] Is Null And [Actual_Number_Of_Employee s]>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)<>"lea ver"));
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
FROM tblCompany INNER JOIN tblStaff ON tblCompany.Managed_Account
GROUP BY tblStaff.Full_Name, tblCompany.Managed_Account
HAVING (((tblStaff.Manager)<>"lea
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.