完整错误是:
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;
答案 0 :(得分:1)
一个或多个子查询返回多行数据,在一个只能返回一个数据的上下文中。例如你有这样的事情发生了:
1234 1121
sum(amardate) + 5678 AS now + 3141 AS last
9101 5161
其中1234
,1121
等是子查询返回的额外行。现在DB做了什么?它不知道您想要将多个值添加到一起。它也不能将这一行结果神奇地分成三个新行,因为它不知道如何进行拆分。
您需要确保两个子查询只能返回 ONE 结果行,包含 ONE 单个值。