子查询返回的值超过1。当子查询跟随=,!=,> =或子查询用作表达式时,不允许这样做。 [英] Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, , >= or when the subquery is used as an expression.

查看:75
本文介绍了子查询返回的值超过1。当子查询跟随=,!=,> =或子查询用作表达式时,不允许这样做。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将以下查询语句写入sql server:



I have written the below query statement to sql server:

SELECT  ReferringPhysician.LastName,ReferringPhysician.FirstName,
    (SELECT LocationName FROM RefPhysLocations WHERE ReferringPhysicianID = (SELECT ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%'))   AS LocationName
    FROM    ReferringPhysician
    WHERE   ReferringPhysician.ReferringPhysicianID=(SELECT ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%')







但是,我得到了来自sql server的以下错误消息。



子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。




But, I got the following error message from sql server.

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

推荐答案

您好,



请在子查询中使用TOP 1,例如



Hi,

Please use TOP 1 in sub query like

SELECT  ReferringPhysician.LastName,ReferringPhysician.FirstName,(SELECT TOP 1 LocationName FROM RefPhysLocations WHERE ReferringPhysicianID = (SELECT TOP 1 ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%'))   AS LocationName
FROM    ReferringPhysician
WHERE   ReferringPhysician.ReferringPhysicianID=(SELECT ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%'









如果您有任何疑问,请告诉我。



如果这样,请提供投票如果这是正确的答案,请提出接受答案。:ros:



谢谢,

Imdadhusen


)


Please do let me know, if you have any doubt.

Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen


hi Imdadhusen,



我尝试根据你的声明...再次出现相同的错误消息。



hi Imdadhusen,

i tried based on ur statement... again came the same error msg.

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



< br $>





SELECT  ReferringPhysician.LastName,ReferringPhysician.FirstName,(SELECT TOP 1 LocationName FROM RefPhysLocations WHERE ReferringPhysicianID = (SELECT TOP 1 ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%'))   AS LocationName
FROM    ReferringPhysician
WHERE   ReferringPhysician.ReferringPhysicianID=(SELECT ReferringPhysicianID FROM RefPhysLocations WHERE LocationName LIKE '%'+@keyword+'%'


最后我解决了这个问题。 ..基于以下..





finally i solved the problem...based on below..


SELECT ReferringPhysician.LastName  ,ReferringPhysician.FirstName,RefPhysLocations.LocationName
    FROM    ReferringPhysician LEFT JOIN RefPhysLocations
            ON ReferringPhysician.ReferringPhysicianID = RefPhysLocations.ReferringPhysicianID
    WHERE   LocationName LIKE '%'+@keyword+'%'


这篇关于子查询返回的值超过1。当子查询跟随=,!=,&gt; =或子查询用作表达式时,不允许这样做。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆