-2

我想从数据库中获取当前月份的周年日期,但我做不到。我的查询在下面给出,但它不起作用。

qry = "Select Anniversary_Date From Family_Information WHERE DATEADD(Year,DATEPART(Year, GETDATE()) - DATEPART(Year, Anniversary_Date),Anniversary_Date) >= GETDATE()";
4

3 回答 3

0

WHERE条款

SELECT...FROM...WHERE MONTH(now())=MONTH(GETDATE()) AND YEAR(now())=YEAR(GETDate())

应该工作 - 本月的周年纪念日。我不确定GETDATE()它是什么?

于 2013-10-24T13:26:31.987 回答
0

怎么样

SELECT Anniversary_Date
FROM Family_Information
WHERE ((DATEPART(Year, GETDATE()) = DATEPART(Year, Anniversary_Date)
AND (DATEPART(Month, GETDATE()) = DATEPART(Month, Anniversary_Date))
于 2013-10-24T13:27:13.663 回答
0

尝试这个 ;

 qry = "SELECT Anniversary_Date
FROM Family_Information
WHERE ((DATEPART(Year, GETDATE())) = DATEPART(Year, Anniversary_Date)
AND    (DATEPART(Month, GETDATE())) = DATEPART(Month, Anniversary_Date))" ;
于 2013-10-24T13:28:49.997 回答