[英]This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
I have a problem executing this query. 我在执行此查询时遇到问题。 Please see my code below.
请在下面查看我的代码。
SELECT (SELECT COUNT(FilteredAppointment.activitytypecodename) AS Expr1
FROM FilteredBusinessUnit INNER JOIN
FilteredSystemUser ON FilteredBusinessUnit.businessunitid = FilteredSystemUser.businessunitid INNER JOIN
FilteredAppointment ON FilteredSystemUser.systemuserid = FilteredAppointment.createdby
WHERE (FilteredBusinessUnit.name IN (@Branch))) AS Appointment,
(SELECT COUNT(FilteredLead.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_7 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_7 ON FilteredBusinessUnit_7.businessunitid = FilteredSystemUser_7.businessunitid INNER JOIN
FilteredLead ON FilteredSystemUser_7.systemuserid = FilteredLead.createdby
WHERE (FilteredBusinessUnit_7.name IN (@Branch)) AND (FilteredLead.new_referraltypename = 'Bank Staff')) AS Bank_Staff_Referral,
(SELECT COUNT(FilteredLead_3.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_6 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_6 ON FilteredBusinessUnit_6.businessunitid = FilteredSystemUser_6.businessunitid INNER JOIN
FilteredLead AS FilteredLead_3 ON FilteredSystemUser_6.systemuserid = FilteredLead_3.createdby
WHERE (FilteredBusinessUnit_6.name IN (@Branch)) AND (FilteredLead_3.new_referraltypename = 'Existing Customer')) AS Customer_Referral,
(SELECT COUNT(Filterednew_discoveryinterview.activityid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_5 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_5 ON FilteredBusinessUnit_5.businessunitid = FilteredSystemUser_5.businessunitid INNER JOIN
Filterednew_discoveryinterview ON FilteredSystemUser_5.systemuserid = Filterednew_discoveryinterview.createdby
WHERE (FilteredBusinessUnit_5.name IN (@Branch))) AS Discovery_Interview,
(SELECT COUNT(FilteredLead_2.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_4 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_4 ON FilteredBusinessUnit_4.businessunitid = FilteredSystemUser_4.businessunitid INNER JOIN
FilteredLead AS FilteredLead_2 ON FilteredSystemUser_4.systemuserid = FilteredLead_2.createdby
WHERE (FilteredBusinessUnit_4.name IN (@Branch))) AS Generated_Leads,
(SELECT name FROM FilteredBusinessUnit WHERE (FilteredBusinessUnit.name IN (@Branch ))) AS BRANCH (从FilteredBusinessUnit WHERE(FilteredBusinessUnit.name IN(@Branch))选择名称)AS分支
` `
The code returns results for query run against a single branch. 该代码返回针对单个分支运行查询的结果。 However, an error is thrown with message" Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. " When I select more than one branch.
但是,将引发错误消息“子查询返回了多个值。当子查询遵循=,!=,<,<=,>,> =或将子查询用作表达式时,不允许这样做。”我选择了多个分支。 My guess is that the error occurs when the last block of select statement is run.
我的猜测是,在运行select语句的最后一块时会发生错误。
How can I write this query to display results for multiple branches 如何编写此查询以显示多个分支的结果
Please help me 请帮我
By Selecting the @Branch Variable separately. 通过分别选择@Branch变量。 Here is the Updated code sample
这是更新的代码示例
SELECT MQ.Name AS BranchName,
(SELECT COUNT(FilteredAppointment.activitytypecodename) AS Expr1
FROM FilteredBusinessUnit
INNER JOIN FilteredSystemUser ON FilteredBusinessUnit.businessunitid = FilteredSystemUser.businessunitid
INNER JOINFilteredAppointment ON FilteredSystemUser.systemuserid = FilteredAppointment.createdby
WHERE (FilteredBusinessUnit.name = MQ.Name)) AS Appointment,
(SELECT COUNT(FilteredLead.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_7
INNER JOIN FilteredSystemUser AS FilteredSystemUser_7 ON FilteredBusinessUnit_7.businessunitid = FilteredSystemUser_7.businessunitid
INNER JOIN FilteredLead ON FilteredSystemUser_7.systemuserid = FilteredLead.createdby
WHERE (FilteredBusinessUnit_7.name = MQ.Name) AND (FilteredLead.new_referraltypename = 'Bank Staff')) AS Bank_Staff_Referral,
(SELECT COUNT(FilteredLead_3.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_6 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_6 ON FilteredBusinessUnit_6.businessunitid = FilteredSystemUser_6.businessunitid INNER JOIN
FilteredLead AS FilteredLead_3 ON FilteredSystemUser_6.systemuserid = FilteredLead_3.createdby
WHERE (FilteredBusinessUnit_6.name = MQ.Name) AND (FilteredLead_3.new_referraltypename = 'Existing Customer')) AS Customer_Referral,
(SELECT COUNT(Filterednew_discoveryinterview.activityid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_5 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_5 ON FilteredBusinessUnit_5.businessunitid = FilteredSystemUser_5.businessunitid INNER JOIN
Filterednew_discoveryinterview ON FilteredSystemUser_5.systemuserid = Filterednew_discoveryinterview.createdby
WHERE (FilteredBusinessUnit_5.name = MQ.Name)) AS Discovery_Interview,
(SELECT COUNT(FilteredLead_2.leadid) AS Expr1
FROM FilteredBusinessUnit AS FilteredBusinessUnit_4 INNER JOIN
FilteredSystemUser AS FilteredSystemUser_4 ON FilteredBusinessUnit_4.businessunitid = FilteredSystemUser_4.businessunitid INNER JOIN
FilteredLead AS FilteredLead_2 ON FilteredSystemUser_4.systemuserid = FilteredLead_2.createdby
WHERE (FilteredBusinessUnit_4.name = MQ.Name)) AS Generated_Leads
FROM FilteredBusinessUnit MQ--I Assume this is where the Branch Name Is kept
WHERE MQ.Name In (@Branch)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.