如何在子查询中使用count [英] How to use count inside subquery

查看:1183
本文介绍了如何在子查询中使用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


这篇关于如何在子查询中使用count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆