简体   繁体   English

子查询返回超过 1 个值。 当子查询跟随......或当子查询用作表达式时,这是不允许的

[英]Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression

I know subquery return more than 1 value but I don't know how to change the code.我知道子查询返回超过 1 个值,但我不知道如何更改代码。 Can anyone help me?谁能帮我?

declare @sProjectNumber nvarchar(200)

( select Project from Project_Table where  Project in (
            select case 
            when @sProject is null then (select distinct Project from Project_Table)
            else @sProject end
from Project_Table)
)

I am guessing that you really intend something like this:我猜你真的打算这样:

select Project
from Project_Table
where @sProject is NULL or Project = @sProject;

This will return the project in @sProject or all projects if that value is NULL .如果该值为NULL ,这将返回@sProject中的项目或所有项目。

暂无
暂无

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

相关问题 子查询返回的值超过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; =或用作表达式时,不允许使用 - Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression 子查询返回的值超过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 =, !=, 子查询返回超过 1 个值。 当子查询跟随 =, ,=, &lt;, &lt;=, &gt;, &gt;= 或 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or 子查询返回的值超过1。 当子查询遵循=,!=时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, != 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =…?时,不允许这样做。 - 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 = 子查询返回的值超过1。 当子查询跟随时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM