這是我第一個問題。我剛剛接管了以前的IT人員的SQL報告,我正在努力處理下面的查詢。它突然停止工作兩天前,現在顯示:STATEMENT ERROR(子查詢返回的值超過1)
報告處理過程中發生錯誤。 (rsProcessingAborted) 數據集「DataSet1」的查詢執行失敗。 (rsErrorExecutingCommand) 子查詢返回多個值。當子查詢遵循=,!=,<,< =,>,> =或當子查詢用作表達式時,這是不允許的。該語句已終止。
它停止在第49行:
and (select t.[status] from [ksimakeprod01].[imake].dbo.iSchWOScheduleLine t left join [ksimakeprod01].[imake].dbo.WORKORDER wa on t.WorkOrderKey=wa.WORKORDERKEY where wa.workorderno=wh.WorkOrderNo)<>7
我從我試圖更新多行數據的列錯誤理解......但是這查詢之前的工作......我該如何解決它?
全面查詢:。
if object_id('tempdb..#CCR_TimelineTable') is not null
begin
drop table #CCR_TimelineTable
end
--Populate temp table with opening inventory.
select 'Balance'as'CCStatus'
,case ss.WhseID when 'SH3' then 'FD2' else ss.WhseID end as 'WhseID'
,ss.ItemID,ss.QtyOnHand,ss.UnitMeasID,cast(cast(getdate() as date)as datetime)'Date',cast(''as varchar(max)) as'WOnum',cast(0 as decimal(10,3)) as'QtyPerCS',cast(0 as float)as'TotalWOqtyReq'
into #CCR_TimelineTable
from vdvStockStatus ss
left join timItem i on i.ItemKey=ss.ItemKey
where ss.CompanyID='KSO'
and right(left(i.ItemID,5),2) in('PK','PC')
--Populate table with incoming purchase orders.
insert into #CCR_TimelineTable
select 'Purchas'
,case pl.WhseID when 'SH3' then 'FD2' else pl.WhseID end as 'WhseID'
,pl.ItemID,pl.QtyOpenToRcv,pl.UnitMeasID
,case when datename(dw,pl.PromiseDate) in ('Friday','Thursday','Wednesday')
then dateadd(day,5,pl.PromiseDate)
else dateadd(day,3,pl.PromiseDate) end
,pl.TranID,0,0
from vdvPurchaseOrderLine pl
where pl.CompanyID='KSO'
and right(left(pl.ItemID,5),2) in('PK','PC')
and pl.StatusAsText='Open'
and pl.QtyOpenToRcv>0
and pl.PromiseDate > cast(getdate() as date)
--Populate table with open work orders. With iMake scheduled start times.
insert into #CCR_TimelineTable
select 'WorkOr',w.WhseID,il.ItemID,-(ww.balancequantitytoproduce*wl.MatReqPc),wos.MaterialItemUOM,ww.woschstdate,ww.workorderno,wl.MatReqPc,(ww.balancequantitytoproduce*wl.MatReqPc)
from tmfWorkOrdDetl_HAI wl
left join tmfWorkOrdHead_HAI wh on wh.WorkOrderKey=wl.WorkOrderKey
left join timitem il on il.ItemKey=wl.MatItemKey
left join timItem ih on ih.ItemKey=wl.ProduceItemKey
left join timWarehouse w on w.WhseKey=wl.WhseKey
left join vdvWorkOrderSteps wos on wos.WorkOrderNo=wh.WorkOrderNo and wos.ItemID=il.ItemID
left join (select wh.WORKORDERNO,sch.WOSchStDate,wh.balancequantitytoproduce from [ksimakeprod01].[imake].dbo.iSchWOScheduleLine sch
left join [ksimakeprod01].[imake].dbo.WORKORDER wh on sch.WorkOrderKey=wh.WORKORDERKEY)ww on ww.workorderno=wh.workorderno
where wl.CompanyID='KSO'
and right(left(il.ItemID,5),2) in('PK','PC')
and wh.Complete=0
and ww.WOSchStDate is not null
and (select t.[status] from [ksimakeprod01].[imake].dbo.iSchWOScheduleLine t left join [ksimakeprod01].[imake].dbo.WORKORDER wa on t.WorkOrderKey=wa.WORKORDERKEY where wa.workorderno=wh.WorkOrderNo)<>7
update #CCR_TimelineTable
set Date= cast(getdate()as date)
where CCStatus='WorkOr' and Date<cast(getdate()as date)
--select * from #CCR_TimelineTable
------------------------------------------------------------------------------
/*declare @days as int
declare @PK as varchar(max)
declare @FG as varchar(max)
declare @WO as varchar(max)
declare @cell as varchar(max)
declare @desc as varchar(max)
set @days = 30
set @PK = '%'
set @FG = '%'
set @WO = '%'
set @cell = 'EGW 3+4'
set @desc = 'sain'*/
select w.WhseID,il.ItemID,id.ShortDesc as'PKDesc',wo.RoutingId,rd.ShortDesc as'FGDesc',wo.WorkOrderNo,ww.CellName,ww.WOSchStDate
,(select sum(tl.QtyOnHand) from #CCR_TimelineTable tl where tl.ItemID=il.ItemID and tl.WhseID=w.WhseID and ww.WOSchStDate>=tl.Date)'RunningBalance'
,(select top 1 tl.UnitMeasID from #CCR_TimelineTable tl where tl.ItemID=il.ItemID group by tl.UnitMeasID order by count(tl.UnitMeasID) desc)'UoM'
,inv.FD2,inv.FD2QC,inv.EG2,inv.EG2QC,inv.SH3,inv.SH3QC,inv.AL3
,(select distinct cc.QtyPerCS from #CCR_TimelineTable cc where cc.WOnum=wo.WorkOrderNo and cc.ItemID=il.ItemID)as'QtyReqPerCS'
,(select distinct cc.TotalWOqtyReq from #CCR_TimelineTable cc where cc.WOnum=wo.WorkOrderNo and cc.ItemID=il.ItemID)as'TotalQtyReqWO'
from tmfWorkOrdDetl_HAI wl
left join tmfWorkOrdHead_HAI wh on wh.WorkOrderKey=wl.WorkOrderKey
left join timitem il on il.ItemKey=wl.MatItemKey
left join timItemDescription id on id.ItemKey=il.ItemKey
left join vdvWorkOrder wo on wo.WorkOrderKey=wh.WorkOrderKey
left join timWarehouse w on w.WhseKey=wl.WhseKey
left join timItem ri on ri.ItemID=wo.RoutingId and ri.CompanyID='KSO'
left join timItemDescription rd on rd.ItemKey=ri.ItemKey
left join (select wh.WORKORDERNO,sch.WOSchStDate,wh.CURRENTSTATUS,mc.CellName from [ksimakeprod01].[imake].dbo.iSchWOScheduleLine sch
left join [ksimakeprod01].[imake].dbo.WORKORDER wh on sch.WorkOrderKey=wh.WORKORDERKEY
left join [ksimakeprod01].[imake].dbo.ManufacturingCell mc on mc.CellKey=wh.MANUFACTURINGCELL)ww on ww.workorderno=wo.workorderno
left join (select i.ItemID
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='FD2' and vs.ItemID=i.ItemID),0)as'FD2'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='FD2QC' and vs.ItemID=i.ItemID),0)as'FD2QC'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='EG2' and vs.ItemID=i.ItemID),0)as'EG2'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='EG2QC' and vs.ItemID=i.ItemID),0)as'EG2QC'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='SH3' and vs.ItemID=i.ItemID),0)as'SH3'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='SH3QC' and vs.ItemID=i.ItemID),0)as'SH3QC'
,isnull((select vs.QtyOnHand from vdvStockStatus vs where vs.WhseID='AL3' and vs.ItemID=i.ItemID),0)as'AL3'
from timItem i
where i.CompanyID='KSO'
and right(left(i.ItemID,5),2) in('PK','PC'))inv on inv.ItemID=il.ItemID
where wl.CompanyID='KSO'
and right(left(il.ItemID,5),2) in('PK','PC')
and wh.Complete=0
and (select sum(tl.QtyOnHand) from #CCR_TimelineTable tl where tl.ItemID=il.ItemID and tl.WhseID=w.WhseID and ww.WOSchStDate>=tl.Date)<0
and ww.currentstatus<>'Completed'
and il.ItemID like '%'+ @PK +'%'
and wo.RoutingId like '%'+ @FG +'%'
and wo.WorkOrderNo like '%'+ @WO +'%'
and id.shortdesc like '%'+ @desc +'%'
and ww.cellname in(@cell)
and ww.WOSchStDate < dateadd(day,@days,getdate())
order by ww.WOSchStDate
它工作。感謝您的幫助! – Max