[英]Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression
[英]How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression
完整的错误是:
Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression
查询:
SqlConnection connect = Helper.GetCon;
string query = "select sum(amardate) as[All] ,"+
"(select amardate from Amar where insertdate='" +
DateTime.UtcNow.ToString("s") + "')as[Now]," +
"(select amardate from Amar where insertdate='" +
DateTime.UtcNow.AddDays(-1).ToString("s") + "')as[Last] From Amar";
SqlDataAdapter da = new SqlDataAdapter(query, connect);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
在一个子查询只能返回一个的上下文中,一个或多个子查询返回了多行数据。 例如,您正在发生以下情况:
1234 1121
sum(amardate) + 5678 AS now + 3141 AS last
9101 5161
其中, 1234
, 1121
,等等都是由子查询返回的额外行。 现在数据库做什么? 它不知道您想将这些多个值加在一起。 它也不能仅仅将这一行结果神奇地拆分为三个新行,因为它不知道拆分应该如何进行。
您需要确保两个子查询只能返回一个由一个单一值组成的结果行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.