日期:2014-05-18  浏览次数:20610 次

帮忙看个代码
select
(SELECT  
DISTINCT   t3.docnum
from   itt1   t0  
inner   join   oitt   t1   on   t0.father   =   t1.code  
inner   join   rdr1   t2   on   t1.code   =   t2.itemcode  
inner   join   ordr   t3   on   t2.Docentry   =   t3.Docentry
inner   join   oitm   t4   on   t0.code   =   t4.itemcode
where   t3.canceled= 'N '   and   t3.docstatus   =   'O '   and   t2.linestatus   =   'O '   and   t0.code   =t5.father)   as   销售订单号,  
t5.father   as   上级物料,
t5.code   as   子项物料,
t6.itemname   as   子项物料描述,
t5.quantity   as   子项物料耗用量,
t6.treetype   as   "BOM:P(是)N(否) "
from   itt1   t5
inner   join   oitm   t6   on   t5.code   =   t6.itemcode
where   t5.father   in
(select
t10.code
from   itt1   t10  
inner   join   oitt   t11   on   t10.father   =   t11.code  
inner   join   rdr1   t12   on   t11.code   =   t12.itemcode  
inner   join   ordr   t13   on   t12.Docentry   =   t13.Docentry
inner   join   oitm   t14   on   t10.code   =   t14.itemcode
where   t13.canceled= 'N '   and   t13.docstatus   =   'O '   and   t12.linestatus   =   'O '   and   t14.treetype   = 'P ')

执行后,结果可以出来,但提示:
(所影响的行数为   15   行)
服务器:   消息   512,级别   16,状态   1,行   1
子查询返回的值多于一个。当子查询跟随在   =、!=、 <、 <=、> 、> =   之后,或子查询用作表达式时,这种情况是不允许的。

这是什么原因,如果没有办法解决,是否有什么语句可以忽略错误,不提示出错信息,只给结果


------解决方案--------------------
select
(SELECT
top 1 t3.docnum
from itt1 t0
inner join oitt t1 on t0.father = t1.code
inner join rdr1 t2 on t1.code = t2.itemcode
inner join ordr t3 on t2.Docentry = t3.Docentry
inner join oitm t4 on t0.code = t4.itemcode
where t3.canceled= 'N ' and t3.docstatus = 'O ' and t2.linestatus = 'O ' and t0.code =t5.father) as 销售订单号,
t5.father as 上级物料,
t5.code as 子项物料,
t6.itemname as 子项物料描述,
t5.quantity as 子项物料耗用量,
t6.treetype as "BOM:P(是)N(否) "
from itt1 t5
inner join oitm t6 on t5.code = t6.itemcode
where t5.father in
(select
t10.code
from itt1 t10
inner join oitt t11 on t10.father = t11.code
inner join rdr1 t12 on t11.code = t12.itemcode
inner join ordr t13 on t12.Docentry = t13.Docentry
inner join oitm t14 on t10.code = t14.itemcode
where t13.canceled= 'N ' and t13.docstatus = 'O ' and t12.linestatus = 'O ' and t14.treetype = 'P ')