sql server 2008中的Datepart函数

时间:2014-05-27 17:04:41

标签: sql sql-server sql-server-2008

我遇到了datepart month函数的问题 该文件清楚地显示了本月的日期,即5月23日,当我放入datepart(MM,t0.DocDate)=DATEPart(MM,GETDATE())时,结果为空。 我想知道什么是错的。奇怪的是,它适用于本月23日之前的任何文档,但不会在此之后。

select 
   t0.itemcode,
   t1.docnum,
   t0.treetype,
   t1.docdate,
   docstatus,DATEPART(MM,Getdate()),DATEPART(MM,t1.docdate)

from 
   RDR1 t0
inner join ORDR t1 on t1.DocEntry=t0.docentry
inner join dbo.OITM t2 on t2.ItemCode=t0.ItemCode
where 
  t1.DocNum=74464 and datepart(MM,t0.DocDate)=DATEPart(MM,GETDATE()) and
  datepart(YY,t0.DocDate)=DATEPART(YY,Getdate())
  and t1.canceled<>'Y' and
  numatcard not like '%Demo%' and t0.TreeType in ('S','N')
  and t1.U_BP2 is null 

0 个答案:

没有答案
相关问题