Use Count criteria as row header

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 16
Reputation: spinnaret is an unknown quantity at this point 
Solved Threads: 1
spinnaret spinnaret is offline Offline
Newbie Poster

Use Count criteria as row header

 
0
  #1
Oct 1st, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 16
Reputation: spinnaret is an unknown quantity at this point 
Solved Threads: 1
spinnaret spinnaret is offline Offline
Newbie Poster

Re: Use Count criteria as row header

 
0
  #2
Oct 2nd, 2008
  1. SELECT Salesperson,
  2. SUM(CASE WHEN Outcome = '0' THEN 1 ELSE 0 END) AS Outcome0,
  3. SUM(CASE WHEN Outcome = '1' THEN 1 ELSE 0 END) AS Outcome1,
  4. SUM(CASE WHEN Outcome = '2' THEN 1 ELSE 0 END) AS Outcome2,
  5. SUM(CASE WHEN Outcome = '3' THEN 1 ELSE 0 END) AS Outcome3,
  6. SUM(CASE WHEN Outcome = '4' THEN 1 ELSE 0 END) AS Outcome4,
  7. SUM(CASE WHEN Outcome = '18' THEN 1 ELSE 0 END) AS Outcome18
  8. FROM Schedules
  9. WHERE IndustryDivision = 10
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC