简体   繁体   English

如何解决错误:“子查询返回了多个值”。 当子查询遵循=,!=,<,<=,>,> =或用作表达式时,不允许使用

[英]How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression

The full error is: 完整的错误是:

Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression

The query: 查询:

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;

One or more of your subqueries returned multiple rows of data, in a context where it can only ever return one. 在一个子查询只能返回一个的上下文中,一个或多个子查询返回了多行数据。 eg you've got something like this happening: 例如,您正在发生以下情况:

                  1234          1121
sum(amardate)  +  5678 AS now + 3141 AS last
                  9101          5161

where the 1234 , 1121 , etc... are the extra rows returned by the subquery. 其中, 12341121 ,等等都是由子查询返回的额外行。 Now what does the DB do? 现在数据库做什么? It has no idea WHICH of those multiple values you want to add together. 它不知道您想将这些多个值加在一起。 It also can't just magically split this one row result into three new rows, because it has no idea HOW the split should occur. 它也不能仅仅将这一行结果神奇地拆分为三个新行,因为它不知道拆分应该如何进行。

You need to make sure the two subqueries can return only ONE result row, consisting of ONE single value. 您需要确保两个子查询只能返回一个一个单一值组成的结果行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 子查询返回超过 1 个值。 当子查询跟随......或当子查询用作表达式时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression 子查询返回的值超过1。 当子查询遵循&gt; =或将子查询用作表达式时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows>= or when the subquery is used as an expression 如何修复此错误“子查询返回了 1 个以上的值。当子查询跟随 =、!=、&lt;、&lt;=、&gt;、&gt;=”时,不允许这样做 - How to fix this error "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >=" 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做。 返回了多个值。 - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. More than 1 value was returned. 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression SQL Server子查询返回了多个值。 当子查询跟随(字符)或子查询用作表达式时,不允许这样做 - SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows (chars) or when the subquery is used as an expression 子查询返回的值超过1。 当子查询遵循=,!= 、、&gt; =或将子查询用作expr时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, , >= or when the subquery is used as an expr 子查询返回的值超过1。 当子查询跟随=,!=时,不允许这样做, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, 子查询返回的值超过1。 当子查询遵循=,!=,&lt;, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, 子查询返回的值超过1。 当子查询遵循=,!=, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM