从SQL Server中选择记录,如果6个月以上 [英] Select records from SQL Server if greater than 6 months
本文介绍了从SQL Server中选择记录,如果6个月以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个MVC应用程序,我需要发封邮件给所有那些记录值( DateUpdated
)中没有更新客户
表。
I am creating an MVC app where I need to send out an email to all those records whose value (DateUpdated
) are not updated in the Customer
table.
我的客户
表如下所示:
ID (PK)
Name
Address
DateLastUpdated
现在我有这样的MySQL查询:
Now I have this MySql query:
SELECT * FROM users WHERE DateLastUpdated >= NOW() - INTERVAL 6 MONTH
我如何将它写在T-SQL和MVC3执行此任务?请帮助!
How I will write it in T-SQL and perform this task in MVC3? Please help!
推荐答案
您的查询应该是:
SELECT * FROM用户WHERE DateLastUpdated> =使用DateAdd(月,-6,GETDATE())
此外,您可能想要剥离出来的时间部分,以便你只剩下例如日期 2011-04-12 00:00:00.000
您可以使用此:
Additionally, you may want to strip out the time portion so you are left with just the date e.g. 2011-04-12 00:00:00.000
you can use this:
SELECT *
FROM users
WHERE DateLastUpdated >= DateAdd(Month, -6, Cast(Floor(Cast(GetDate() as Float)) as DateTime))
这篇关于从SQL Server中选择记录,如果6个月以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文