Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
CREATE PROCEDURE dbo.StoredProcedure7
AS
SELECT *
FROM 
(SELECT dbo.Districts.name,count(distinct(dbo.Interview_Schedule.app_id)) AS nom,
            CASE  dbo.Interview_Schedule.interview_result
            WHEN NULL THEN 'no value'
            WHEN 0 THEN 'zero'
            WHEN 1 THEN 'one'
            END AS thevalue
 FROM Districts INNER JOIN
      Interview_Schedule ON Districts.id = Interview_Schedule.interview_district 
 WHERE dbo.Interview_Schedule.work_flow_id=1
 group by dbo.Districts.name)AS datatable
 PIVOT
( COUNT(thevalue)
  FOR thevalue IN ([no value],[zero],[one])) as piv







ERROR ::

Msg 8120, Level 16, State 1, Procedure StoredProcedure7, Line 3
Column 'Interview_Schedule.interview_result' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Procedure StoredProcedure7, Line 3
Column 'Interview_Schedule.interview_result' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Posted
Updated 15-Feb-11 3:03am
v2

 
Share this answer
 
Comments
Nish Nishant 13-Feb-11 20:46pm    
I am pretty sure you can't add the result of a Count() to a Group By clause.
MohammedSabry 13-Feb-11 20:50pm    
so if you please what`s the error in the first statement ??
Nish Nishant 13-Feb-11 20:52pm    
Remove dbo.Interview_Schedule.interview_result from the Select. You'll have to get that info through an inner join on the same table. That should fix your problem. Also remove that Count() stuff from the Group By clause - that is not permitted.
MohammedSabry 13-Feb-11 20:58pm    
can you write it ?
Nish Nishant 13-Feb-11 21:00pm    
I don't really know your table structure and what exactly it is that you are trying to do. Can you describe the columns in the tables and what exactly you are trying to do here? (you can improve your question instead of adding a comment). That way I (or someone else) will be able to help you better.
Remove dbo.Districts.name from your query and it should work fine.
 
Share this answer
 
Comments
MohammedSabry 14-Feb-11 9:08am    
it didn`t
SQL
select D.[Name] as [District Name], sum(case when I.Interview_Result = 1 then 1 end) as [Count of 1],
sum(case when I.Interview_Result = 0 then 1 end) as [Count of 0],
sum(case when I.Interview_Result IS NULL then 1 end) as [Count of NULLs]
from Districts D inner join Interview_Schedule I on D.ID = I.Interview_District
GROUP BY D.[ID],D.[Name]

(copied)


i found it ..
 
Share this answer
 
Comments
Yusuf 14-Feb-11 12:58pm    
May be you should update your subject with [SOLVED]. So, people know you got it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900