我怎么......解决这个问题 [英] How do i...solve this

查看:69
本文介绍了我怎么......解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个子查询,但它给了我这条消息:消息512,级别16,状态1,行1子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。



我尝试过:



(从v_accounts c中选择(d.ProductID),t_DormantAccounts d where(c.ProductID like( 'sav9%')或c.ProductID喜欢('cur9%'))

和c.AccountID = d.AccountID和c.OurBranchID = d.OurBranchID)作为OriginalBranchID,

i wrote this sub query but it give me this message:Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

What I have tried:

( select (d.ProductID) from v_accounts c,t_DormantAccounts d where (c.ProductID like ('sav9%') or c.ProductID like ('cur9%'))
and c.AccountID=d.AccountID and c.OurBranchID=d.OurBranchID ) as OriginalBranchID,

推荐答案

查看您的查询:

Look at your query:
SELECT (d.ProductID) FROM v_accounts c, t_DormantAccounts d
   WHERE (c.ProductID LIKE ('sav9%') 
          OR c.ProductID LIKE ('cur9%'))
     AND c.AccountID=d.AccountID 
     AND c.OurBranchID=d.OurBranchID

单独运行它(SSMS对此有好处)并且它将返回多行。

SQL不能使用多个结果作为子查询时,您需要更改它以返回单个值:

Run that in isolation (SSMS is good for that) and it will return more than one row.
SQL can't work with more than one result where you are using that as a subquery - so you need to either alter that to return a single value:

SELECT TOP 1 (d.ProductID) FROM ...
   ORDER BY ...

或者计算一个只能返回单个值的查询。



唯一的另一种选择是查看整个查询可能使用JOIN来计算你想要达到的目标。



但我们不能为你做任何事情:我们d没有任何访问你的数据库,外部查询,或任何你想要得到的结果。

Or work out a query that will only ever return a single value.

The only other alternative is to look at the whole query that is a part of and work out what you are trying to achieve better, possibly using JOIN.

But we can't do any of that for you: we don't have any access to your DB, the "outer query", or any idea what you are expecting to get as results.


(select top 1 (d.ProductID) from v_accounts c,t_DormantAccounts d where (c.ProductID like ('sav9%') or c.ProductID like ('cur9%'))
and c.AccountID=d.AccountID and c.OurBranchID=d.OurBranchID ) as OriginalBranchID


这篇关于我怎么......解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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