where 后面如何用条件判断语句?
set nocount ONselect MAX( b.FDate) as FDate2,a.FOrderInterID,a.FItemID
into #ta01
from ICStockBillEntry a
left join ICStockBill b on a.FInterID =b.FInterID
where b.FCancellation =0
group by a.FOrderInterID,a.FItemID
select b.FDate as 制单日期,b.FBillNo as 编号,
case b.FStatus when 0 then '未审核' when 3 then '关闭' else '审核' end as 状态,
case a.FMrpClosed when 0 then '未关闭' else '关闭' end as 行状态,
c.FNumber as 供应商代码,c.FName as 供应商名称,d.FNumber as 物料代码,d.FName as 物料名称,d.FModel as 物料规格,e.FNumber as 单位,
a.FQty as 采购订单数量,a.FStockQty as 入库数量,欠采购订单数量=a.FStockQty-a.FQty,a.FDate as 交货日期,g.FDate as 申请日期,
h.FDate2 as 最后进料日期,
case when h.FDate2 > a.FDate then '托期' when h.FDate2 < a.FDate then '提前' else '准时' end as 交期达成状况,
提前托期天数=DATEDIFF(DAY,h.FDate2,a.FDate)
into #ta02
from POOrderEntry a /*采购订单表体*/
left join POOrder b on a.FInterID = b.FInterID /*采购订单表头*/
left join t_Supplier c on b.FSupplyID =c.FItemID /*供应商表*/
left join t_ICItem d on a.FItemID =d.FItemID /*产品表*/
left join t_MeasureUnit e on a.FUnitID =e.FMeasureUnitID /*计量单位表*/
left join PORequestEntry f on a.FSourceInterId =f.FInterID /*采购申请单表体*/
left join PORequest g on f.FInterID =g.FInterID /*采购申请单表头*/
left join #ta01 h on a.FInterID =h.FOrderInterID /**外购入库-最近时间*/
where b.FCancellation =0 and a.FSourceEntryID =f.FEntryID and g.FCancellation =0 and a.FItemID =h.FItemID
and a.FDate >= '********'
and a.FDate <= '########'
and c.FNumber like '%@SuppNo@%'
and c.FName like '%@SuppName@%'
and b.FBillNo like '%*FBillNoCommon*%'
AND d.FNumber like '%@@ItemNumber@@%'
and d.FName like '%@ItemName@%'
order by b.FDate asc,b.FBillNo asc
select 序号=IDENTITY (int,1,1), * into #ta03 from #ta02
select * from #ta03
drop table #ta01
drop table #ta02
drop table #ta03
----------------------------------------------------------------------------
以上是自定义报表,已符合采购部申请的需求。但有一点就是不好用,请各位指导:
and a.FDate >= '********' --起始日期
and a.FDate <= '########' --截止日期
一定要录入这2个日期后面的条件才起作用,反之若不录入日期则查询不到任务数据。
我有这个想法,就是实现不了:
若“起始日期”是 NULL(不录入内容),则是'1900-01-01 00:00:00.000'
若“截止日期”是 NULL(不录入内容),,则是'9999-01-01 00:00:00.000'
这样就可达到效果了,请各位指导
[ 本帖最后由 pxr 于 2011-12-15 21:00 编辑 ]