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?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.