如何在sql server中检索当前月份日期值 [英] How to retrieve current month date values in sql server

查看:81
本文介绍了如何在sql server中检索当前月份日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下查询以根据他们的emi付款检索用户记录





i have written following query to retrieve user records based on their emi payments


SELECT 
    PaymentTracker1.*
    ,DATEADD(m,N,StartDate) AS DueDate
    , CASE WHEN GETDATE() > StartDate THEN (Numbers.N - DATEDIFF(m,StartDate,GETDATE())) * MonthlyPay ELSE Numbers.N * MonthlyPay END AS DueAmount
FROM 
    PaymentTracker1 
    INNER JOIN Numbers on DATEDIFF(m,PaymentTracker1.StartDate,PaymentTracker1.EndDate) >= Numbers.N where DueDate is current date
ORDER BY
    PaymentTracker1.Name
    ,Numbers.N



$ / b $ b



通过使用此查询所有记录显示..out将该查询的图像点击下面的链接



http://i.stack.imgur.com/crl7M.png



因为我想只显示这条记录(仅限当前月份记录,如果它被越过然后显示下个月记录)



49 Ajay Merugu Chit 200000 11000 24 09/01/2015 09/01/2017 99893201276 South Swaroop Nagar Uppal Hyderabad 2015-10-01 00:00:00.000 0





by using this query all records are displaying ..out put image of that query is click below link

http://i.stack.imgur.com/crl7M.png

in that i want to display only this record(only current month record if it is crossed then show next month record )

49 Ajay Merugu Chit 200000 11000 24 09/01/2015 09/01/2017 99893201276 South Swaroop Nagar Uppal Hyderabad 2015-10-01 00:00:00.000 0

推荐答案

使用代码

Use The Code
where datepart(m,DueDate)= datepart(m,getdate()) AND datepart(yy,DueDate)= datepart(yy,getdate())


SELECT DATEPART(MM,GETDATE())



此查询将更具体地获取当前月份
SELECT DATEPART(MM,GETDATE())

this query will be more specific to get the current month


这篇关于如何在sql server中检索当前月份日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆