title: STATEMENT ERROR (Subquery returned more than 1 value)
body: <p>This is my very first question. I have just took over SQL reports from the previous IT guy and I'm struggling with the query below. It suddenly stopped working two days ago and now showing:</p>
  
  <p>An error has occurred during report processing. (rsProcessingAborted)
  Query execution failed for dataset 'DataSet1'. (rsErrorExecutingCommand)
  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , >, >= or when the subquery is used as an expression. The statement has been terminated.</p>
  
  <p>It stops on line 49:</p>
  
  <pre><code>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)&lt;&gt;7
  </code></pre>
  
  <p>I understand from the error that I'm trying to update a column with multiple row data...however this query worked before... How can I fix it?</p>
  
  <p>Full query:</p>
  
  <pre><code>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&gt;0
  and pl.PromiseDate &gt; 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)&lt;&gt;7
  
  update #CCR_TimelineTable
  set Date= cast(getdate()as date)
  where CCStatus='WorkOr' and Date&lt;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&gt;=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&gt;=tl.Date)&lt;0
  and ww.currentstatus&lt;&gt;'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 &lt; dateadd(day,@days,getdate())
  
  order by ww.WOSchStDate
  </code></pre>