문제

i have this table:

Players:
ID (int)
Birthday (datetime)

I need choose 3 first players, which have birthday in the actual month... I have this but the result is nothing.. Have you any idea?

SELECT * 
FROM Players
WHERE Birthday < DATEADD(month, -2, GETDATE())
도움이 되었습니까?

해결책 2

Using SQL Server syntax:

select  top 3 *
from    YourTable
where   datepart(month, Birthday) = datepart(month, getdate())

다른 팁

You need to use DATEPART function in SQL server

SELECT * 
FROM Players
WHERE DATEPART(MM,Birthday) = DATEPART(MM,GETDATE())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top