![](/img/trans.png)
[英]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.