如何检索当前月份日期值

时间:2015-11-03 07:34:35

标签: sql-server

我编写了一个查询来从开始日期和结束日期检索当前月份值。我现在的月份以及明年的价值也会回归

这是我的查询

SELECT 
    PaymentTracker1.*
    , convert(varchar(20),DATEADD(m,N,StartDate),110) AS DueDate
    ,(Numbers.N * MonthlyPay) AS DueAmount
FROM 
    PaymentTracker1 
    INNER JOIN Numbers on DATEDIFF(m,PaymentTracker1.StartDate,PaymentTracker1.EndDate) >= Numbers.N 

    where  datepart(mm,DATEADD(mm,N,StartDate))= datepart(mm,getdate()) and  datepart(yy,DATEADD(y,N,StartDate))= datepart(yy,getdate())
ORDER BY
PaymentTracker1.Name
,Numbers.N

我明年也会获得月份价值,

如何仅返回当前月份和年份值

0 个答案:

没有答案