0

I need to write a stored procedure to analyse appointments for the last 12 months.

I need to get each salesperson (by ID) and for each person carry out a count of the number of appointments and count them by outcome (sale, second meeting , failure etc.) and then display them with
Salesperson, Count Sale, Count 2nd Meeting, Count Failure

Any one got any code snippets for this?

1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by spinnaret
0
SELECT 		Salesperson,
		SUM(CASE WHEN Outcome = '0' THEN 1 ELSE 0 END) as Outcome0,
		SUM(CASE WHEN Outcome = '1' THEN 1 ELSE 0 END) as Outcome1,
 		SUM(CASE WHEN Outcome = '2' THEN 1 ELSE 0 END) as Outcome2,
     		SUM(CASE WHEN Outcome = '3' THEN 1 ELSE 0 END) as Outcome3,
		SUM(CASE WHEN Outcome = '4' THEN 1 ELSE 0 END) as Outcome4,
     		SUM(CASE WHEN Outcome = '18' THEN 1 ELSE 0 END) as Outcome18
FROM		Schedules
WHERE 		IndustryDivision = 10
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.