显示两个日期之间的记录 [英] Displaying Records Beteen two dates
问题描述
请有人帮帮我,我需要显示使用月份介于两个日期(包括两个月)之间的记录.假设以下数据是我的数据;
SN名FIRSTPAY_DATE RECOVERY_DATE
1.丹尼斯2010年6月30日22/02/2011
2. KAY 10/03/2010 05/07/2010
3.简(JANE)2010年6月1日2010年2月3日
4. LOLA 2010年3月8日2011年10月10日
如果我需要使用2010年7月显示介于FIRSTPAY_DATE和RECOVERY_DATE之间的记录,则应显示以下记录;
SN名FIRSTPAY_DATE RECOVERY_DATE
1.丹尼斯2010年6月30日22/02/2011
2 KAY 10/03/2010 05/07/2010
请帮助
Please can someone help me out, I need to display records that falls in between two dates inclusive using the month. Assuming data below is my data;
SN NAME FIRSTPAY_DATE RECOVERY_DATE
1. DENIS 30/06/2010 22/02/2011
2. KAY 10/03/2010 05/07/2010
3. JANE 06/01/2010 03/02/2010
4. LOLA 03/08/2010 10/10/2011
If I need to display record that falls in between FIRSTPAY_DATE AND RECOVERY_DATE using july 2010 the following record should be displayed;
SN NAME FIRSTPAY_DATE RECOVERY_DATE
1. DENIS 30/06/2010 22/02/2011
2 KAY 10/03/2010 05/07/2010
Please help
推荐答案
Select *
From tablename
Where year(@date) between year(firstpay_day) and
year(recovery_date) and month(@date) between month(firstpay_day)
and month(recovery_date)
试试看
Give that a try
Try:
SELECT * FROM myTable where @date >= FIRSTPAY_DATE AND @date <= RECOVERY_DATE
这应该是您想要的-尽管未测试性能
This should be what you are after - not tested the performance though
declare @date datetime
set @date = ''10 july 2010''
SELECT * FROM myTable where CAST(CAST(DATEPART(year, @date) as varchar(50)) + ''-'' + CAST(DATEPART(month, @date) AS varchar) + ''-1'' AS DATETIME) between FIRSTPAY_DATE AND RECOVERY_DATE
修复了较小的拼写错误
Fixed minor spelling error
这篇关于显示两个日期之间的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!