求教 金蝶自定义报表SQL语句实现,像第一个例子这样的过滤条件要怎么实现。,
-----------------lz_xiaohe------------20080427
Set Nocount on
Create Table #TempInventory(
[FBrNo] [varchar] (10) NOT NULL ,
[FItemID] [int] NOT NULL ,
[FBatchNo] [varchar] (200) NOT NULL ,
[FStockID] [int] NOT NULL ,
[FQty] [decimal](28, 10) NOT NULL ,
[FBal] [decimal](20, 2) NOT NULL ,
[FStockPlaceID] [int] NULL ,
[FKFPeriod] [int] NOT NULL Default(0),
[FKFDate] [varchar] (255) NOT NULL ,
[FMyKFDate] [varchar] (255),
[FStockTypeID] [Int] NOT NULL,
[FQtyLock] [decimal](28, 10) NOT NULL,
[FAuxPropID] [int] NOT NULL,
[FSecQty] [decimal](28, 10) NOT NULL
)
Insert Into #TempInventory
Select u1.FBrNo,u1.FItemID,u1.FBatchNo,u1.FStockID,u1.FQty,u1.FBal,u1.FStockPlaceID,
u1.FKFPeriod,ISNULL(u1.FKFDate,''),ISNULL(u1.FKFDate,''),500,u1.FQtyLock,u1.FAuxPropID,u1.FSecQty
From ICInventory u1 left join t_ICItem t1 on u1.FItemID = t1.FItemID
left join t_Stock t2 on u1.FStockID=t2.FItemID
left join t_MeasureUnit t3 on t1.FUnitID=t3.FMeasureUnitID
left join t_MeasureUnit t4 on t1.FStoreUnitID=t4.FMeasureUnitID
left join t_StockPlace t5 on u1.FStockPlaceID=t5.FSPID
where u1.FQty<>0 and t1.FDeleted=0
Insert Into #TempInventory
Select u1.FBrNo,u1.FItemID,u1.FBatchNo,u1.FStockID,u1.FQty,u1.FBal,u1.FStockPlaceID,
u1.FKFPeriod,ISNULL(u1.FKFDate,''),ISNULL(u1.FKFDate,''),u1.FStockTypeID,0,u1.FAuxPropID,u1.FSecQty
From POInventory u1 left join t_ICItem t1 on u1.FItemID = t1.FItemID
left join t_Stock t2 on u1.FStockID=t2.FItemID
left join t_MeasureUnit t3 on t1.FUnitID=t3.FMeasureUnitID
left join t_MeasureUnit t4 on t1.FStoreUnitID=t4.FMeasureUnitID
left join t_StockPlace t5 on u1.FStockPlaceID=t5.FSPID
where u1.FQty<>0 and t1.FDeleted=0
Select t1.FNumber AS FMaterialNumber,t1.FName as FMaterialName,t1.FModel as FMaterialModel,
--t19.FName as FSecUnitName,
u1.FBatchNo,t2.FNumber AS FStockNumber, t2.FName as FStockName ,
t3.FName as FBUUnitName,u1.FQty as FBUQty,
t4.FName as FCUUnitName ,u1.FQty/t4.FCoefficient as FCUUQty,
--u1.FQtyLock as FBUQtyLock,u1.FQtyLock/t4.FCoefficient as FCUUQtyLock,
--t5.FName as FSPName,
u1.FKFPeriod,--保质期天数
case when isdate(u1.FKFDate)=1 then Convert(datetime,u1.FKFDate) else null end as FKFDate,--采购日期
case when isdate(u1.FMyKFDate)=1 then Convert(datetime,u1.FMyKFDate) else null end as FMyKFDate,--当前保质期
Case when isdate(u1.FKFDate)=0 then null else Convert(datetime,u1.FKFDate) + u1.FKFPeriod END AS FMaturityDate,--到期日
t31.Fname Fauxstaockname
,t31.FCoefficient--换算系数
,FLOOR(u1.Fqty/t31.FCoefficient) Fauxstockqty--辅助单位数量
,(u1.Fqty-(FLOOR(u1.Fqty/t31.FCoefficient)*t31.FCoefficient)) FFstockDiff--余数
--上面这一行的作用,是根据辅助单位的名称,计算出辅助单位数量和余数
-- ,t1.FQtyDecimal, t1.FPriceDecimal,0 as FSumSort,
-- t5.FNumber as FSPNumber,t4.FNumber as FCUUnitCode,t4.FMeasureunitID as FCUUnitID
-- ,t1.FitemID ,T2.FitemID FStockID,T5.FSPID FSPID,t9.FName as FAuxPropName,t9.FNumber as FAuxPropNumber,u1.FSecQty
From #TempInventory u1
left join t_ICItem t1 on u1.FItemID = t1.FItemID
left join t_Stock t2 on u1.FStockID=t2.FItemID
left join t_MeasureUnit t3 on t1.FUnitID=t3.FMeasureUnitID
left join t_MeasureUnit t4 on t1.FStoreUnitID=t4.FMeasureUnitID
left join t_StockPlace t5 on u1.FStockPlaceID=t5.FSPID
left join t_AuxItem t9 on u1.FAuxPropID=t9.FItemID
left join t_Measureunit t19 on t1.FSecUnitID=t19.FMeasureunitID
left join (select * from t_measureunit where fstandard<>1) t31 on t31.Funitgroupid=t1.funitgroupid
left join (SELECT FTypeID,FInterID FItemID, FID FNumber,FName,FSpec
FROM t_SubMessage Where FInterID>0 AND FDeleted=0 And FTypeID=30 ) t32 on t32.FName=t31.Fname
where u1.FQty<>0 and t1.FDeleted=0
and {fnumberfrom} and {fnumberEnd}
and {fstocknumberfrom} and {fstocknumberEnd}-- AND t2.FItemID=178
--and t1.fnumber>='10.10.1.10' and t1.fnumber<='10.10.1.10'
--and t2.fnumber>='1' and t2.fnumber<='1'
Order By t1.FNumber,u1.FBatchNo
Drop Table #TempInventory
这是第一个表,,已经可以实现 过滤功能 如红色字体部分