如何在子查询中使用count
问题描述:
Msg 512, Level 16, State 1, Procedure usp_GetSummaryReportForCompAdmin, Line 11
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
我收到此错误
I am getting this error
Select COUNT(*) from QualificationDevelopments where AddedForId = e.Id and (DataForYear in (Select DataForYear from QualificationDevelopments))
and Status <> 4
) as TotalDevelopments,
I want the count of all years present in this column. but it is throwing an exception
答
我不确定只是给一试。我刚刚修改了一个子查询。
I am not sure just give it a try. I have just modified one of the sub query.
(Select COUNT(*) from QualificationDevelopments where AddedForId = e.Id and (@DataForYear Is Null or QualificationDevelopments.DataForYear = @DataForYear )) and Status <> 4 ) as TotalDevelopments