select t1.fnumber as 物料代码,t1.FName as 物料名称,t1.FModel as 规格型号 ,t2.FName as 仓库, w1.fqty as 即时库存
 From ICInventory w1,t_ICItem t1,t_Stock t2,t_MeasureUnit t3,t_MeasureUnit t4

 Where   w1.FItemID=t1.FItemID And
         w1.FStockID=t2.FItemID And
         w1.FQty<>0 And
         t1.FUnitID=t3.FMeasureUnitID And
         t1.FStoreUnitID=t4.FMeasureUnitID And
 w1.FItemID in
 (
   Select S.FItemID 
     From 
      (Select  v1.FItemID,u1.FDate 
         from ICStockBill u1 
       inner join ICStockBillEntry v1 on u1.FInterID=v1.FInterID And  u1.FCancellation=0 
       Union All 
       Select u1.FItemID,u1.FStockInDate as FDate 
     From  ICInvInitial u1 
     Where u1.Fbegqty <> 0) S 
   group by S.FItemID 
   Having DateDiff(DD, Max(FDate), GetDate()) > 91

 )
 And t1.FNumber>='03.01.0001' And t1.FNumber<='03.02.0262' And t2.FTypeID<>502

 Group By t1.FItemID,t1.FNumber,t1.FShortNumber,t1.FName,t1.FModel,w1.FBatchNo,
          w1.FStockID,t2.FNumber,t2.FShortNumber,t2.FName,
          t3.FName , t4.FName,w1.fqty
 Order By t1.FNumber,t2.FNumber