| | |
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:
Solved Threads: 1
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?
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?
•
•
Join Date: Sep 2008
Posts: 16
Reputation:
Solved Threads: 1
MS SQL Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the MS SQL Forum
- Previous Thread: display all the records in table in SQL using VBScript in ASP
- Next Thread: Pagination confusion
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger getdate highperformancecomputing hpc hpcserver2008 ibm iis loop maximum microsoft ms mssql multiple multithreading news number permission query reporting result server services sets source sql sqlserver sqlserver2005 supercomputing tables uniqueid update view weekday





