我正在尝试使用以下代码列出本周过生日的人:
declare @START_DATE date;
set @START_DATE = DATEADD(dd, 1 - DATEPART(dw, getdate()), getdate())
declare @END_DATE date;
set @END_DATE = DATEADD(dd,6, @START_DATE)
set DATEFIRST 1
SELECT @START_DATE as StartDate, Personel.DogumTarihi , @END_DATE as EndDate
,[Adi]
,[Soyadi]
,[BirimAdi]
,[DogumTarihi]
,[MudurlukAdi]
,[Gorevi]
,[CepTelefonu]
,[EvTelefonu]
from Personel
where (
DATEPART(m, Personel.DogumTarihi) = DATEPART(m, @START_DATE)
and DATEPART(DAY, Personel.DogumTarihi) >= DATEPART(DAY, @START_DATE)
and DATEPART(DAY, Personel.DogumTarihi) <= DATEPART(DAY, @END_DATE)
)
OR (
DATEPART(m, Personel.DogumTarihi) = (DATEPART(m, @START_DATE)+ 1)
and DATEPART(DAY, Personel.DogumTarihi) <= DATEPART(DAY, @END_DATE)
)
首先我设置开始日期并根据开始日期计算结束日期。然后我将星期一设置为一周的第一天。但是每次我运行它时,我都会收到一个不同的开始日期。我对 Ms Sql Scripting 很陌生,我可能在声明中做错了什么,但我找不到它。提前致谢。