gpt4 book ai didi

sql - 如何在两个日期和月份而不是年份之间获取记录?

转载 作者:行者123 更新时间:2023-12-02 08:31:44 25 4
gpt4 key购买 nike

I have following records

NAME       BIRTHDATE 
A 19/09/1990
B 25/09/1992
C 26/09/1993

当前日期是 19/09/2014我想获取从当前日期到接下来 7 天的生日记录,下面是我的查询。

CREATE PROCEDURE [dbo].[Get_Birthday]
as
begin
Declare @CurrentDate date ,@NxtDate date

set @CurrentDate = GETDATE();
set @NxtDate = DATEADD(day,7,getdate())
print @CurrentDate
print @NxtDate
select DocId, DoctorName,DOA,Email from vw_DoctorDetail
where DOA between @CurrentDate and @NxtDate
end

最佳答案

你可以试试下面的方法

CREATE PROCEDURE [dbo].[Get_Birthday]
as
beginDeclare @CurrentDate date ,@NxtDate date

set @CurrentDate = DATEADD(year,-DATEDIFF(year,'19000101',GETDATE()),GETDATE());
set @NxtDate = DATEADD(day,7,@CurrentDate)
print @CurrentDate
print @NxtDate
select DocId, DoctorName,DOA,Email from vw_DoctorDetail
WHERE DATEADD(year,-DATEDIFF(year,'19000101',DOA),DOA) between @CurrentDate and @NxtDate

关于sql - 如何在两个日期和月份而不是年份之间获取记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25930127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com