当前位置: 代码迷 >> Sql Server >> 时间限制范畴的SQL语句
  详细解决方案

时间限制范畴的SQL语句

热度:42   发布时间:2016-04-24 09:20:48.0
时间限制范围的SQL语句
select 
a.fpuremp,a.fpurno,b.frecdate,c.fprvnname,i.fgoodscode,[fgoodsnameexp]=case when i.fifcategory='1' then b.fgoodsname else i.fgoodsname end,[fsizedescexp]=case when i.fifcategory='1' then b.fsizedesc else i.fsizedesc end,b.finvqty,b.fbuyqty,[fbuyunitname]=k.funitname,b.frecqtyofbuyunit,[fnorecqtyofbuyunit]=case when b.finvqty-isnull(n.ftmprecqtyofinvunit,0)-b.frecqtyofinvunit+b.faddrtnqtyofinvunit>0 then  dbo.fn_getunitexchange(b.fgoodsid,b.finvunit,b.fbuyunit,b.finvqty-isnull(n.ftmprecqtyofinvunit,0)-b.frecqtyofinvunit+b.faddrtnqtyofinvunit) else 0 end,b.frtnqtyofbuyunit,[fifcanceldesc]=dbo.fn_ifcanceldesc(a.fifcancel),b.fordno,b.forino,[fcflagdesc]=dbo.fn_cflagdesc(a.fcflag),[fifclosedesc]=dbo.fn_getendcasedesc(a.fifclose),p.fprinttimes
,fdiffday=datediff(day,b.frecdate,getdate())

From t_PURD_PurMst A with(nolock)  
Left Join  t_PURD_PurItem B with(nolock)   on a.fpurno=b.fpurno
 
Left Join  t_PURM_PrvMst C with(nolock)   on a.fprvcode=c.fprvcode
 
Left Join  t_BOMM_GoodsMst I with(nolock)   on B.fGoodsID=i.fgoodsid
 
Left Join  t_BMSM_UnitMst K with(nolock)   on B.fBuyUnit=K.funitcode
 
Left Join  V_PUR010_HaveTmpRecQty N with(nolock)   on b.fpurno=n.fpurno and b.fsno=n.fpursno
 
Left Join  t_ADMM_RptPrintLogSum P with(nolock)   on P.fSrcFormCode='PUR010_FrmPurchaseOrder' and P.fKeyValue=a.fpurno
 
Left Join  t_BOMM_GoodsLevelItem W with(nolock)   on b.fgoodsid=w.fgoodsid and b.flvlcode=w.flvlcode
 

  where ( a.fschtype= '1') and ((a.fifcancel = '0')
    and  ( Convert(varchar(10),b.frecdate,121)  <= convert(nvarchar(10),DateAdd(Day,3,GetDate()),120)) 
     and ( (dbo. fn_getendcasedesc(a.fifclose) = N'未结案')  or  (dbo. fn_getendcasedesc(a.fifclose) = N'反结案'))) and  ( a.fschtype= '1' )
     and (b.frecqtyofbuyunit<b.fbuyqty)


以上语句是提前三天的所有给显示出来,如果我只想显示昨天到提前3天这之间的东东显不出来,怎么写呢?
------解决思路----------------------

-- 把句,后面的表达式,是当当时间加了 3 天,如果不想加了 3 天。
????and??(?Convert(varchar(10),b.frecdate,121)??<=?convert(nvarchar(10),DateAdd(Day,3,GetDate()),120))?

-- 改3 成就 0 就可以了,或者整个 DateAdd 也不要了,只留下 getdate() 。
????and??(?Convert(varchar(10),b.frecdate,121)??<=?convert(nvarchar(10),DateAdd(Day,0,GetDate()),120))?


------解决思路----------------------
设置个变量代替时间不就行了
------解决思路----------------------

select 
a.fpuremp,a.fpurno,b.frecdate,c.fprvnname,i.fgoodscode,[fgoodsnameexp]=case when i.fifcategory='1' then b.fgoodsname else i.fgoodsname end,[fsizedescexp]=case when i.fifcategory='1' then b.fsizedesc else i.fsizedesc end,b.finvqty,b.fbuyqty,[fbuyunitname]=k.funitname,b.frecqtyofbuyunit,[fnorecqtyofbuyunit]=case when b.finvqty-isnull(n.ftmprecqtyofinvunit,0)-b.frecqtyofinvunit+b.faddrtnqtyofinvunit>0 then  dbo.fn_getunitexchange(b.fgoodsid,b.finvunit,b.fbuyunit,b.finvqty-isnull(n.ftmprecqtyofinvunit,0)-b.frecqtyofinvunit+b.faddrtnqtyofinvunit) else 0 end,b.frtnqtyofbuyunit,[fifcanceldesc]=dbo.fn_ifcanceldesc(a.fifcancel),b.fordno,b.forino,[fcflagdesc]=dbo.fn_cflagdesc(a.fcflag),[fifclosedesc]=dbo.fn_getendcasedesc(a.fifclose),p.fprinttimes
,fdiffday=datediff(day,b.frecdate,getdate())
From t_PURD_PurMst A with(nolock)  
Left Join  t_PURD_PurItem B with(nolock)   on a.fpurno=b.fpurno
Left Join  t_PURM_PrvMst C with(nolock)   on a.fprvcode=c.fprvcode
Left Join  t_BOMM_GoodsMst I with(nolock)   on B.fGoodsID=i.fgoodsid
Left Join  t_BMSM_UnitMst K with(nolock)   on B.fBuyUnit=K.funitcode
Left Join  V_PUR010_HaveTmpRecQty N with(nolock)   on b.fpurno=n.fpurno and b.fsno=n.fpursno
Left Join  t_ADMM_RptPrintLogSum P with(nolock)   on P.fSrcFormCode='PUR010_FrmPurchaseOrder' and P.fKeyValue=a.fpurno
Left Join  t_BOMM_GoodsLevelItem W with(nolock)   on b.fgoodsid=w.fgoodsid and b.flvlcode=w.flvlcode
where ( a.fschtype= '1') and (a.fifcancel = '0')
and  (Convert(varchar(10),b.frecdate,121)  >= convert(nvarchar(10),DateAdd(Day,-1,GetDate()),120)
and  (Convert(varchar(10),b.frecdate,121)  <= convert(nvarchar(10),DateAdd(Day,3,GetDate()),120)
and ( (dbo. fn_getendcasedesc(a.fifclose) = N'未结案')  or  (dbo. fn_getendcasedesc(a.fifclose) = N'反结案'))) and  ( a.fschtype= '1' )
and (b.frecqtyofbuyunit<b.fbuyqty)
  相关解决方案