Link to home
Start Free TrialLog in
Avatar of AVONFRS
AVONFRS

asked on

SQL Select if between dates dynamic month and year

I have a table with a column of dates called COMPDATE
I need to select where is is the current month

So

SELECT COUNT(*) FROM COMPLETEDVISITS WHERE COMPDATE IS > [FIRST OF THE CURRENT MONTH] AND < [31 OF THE CURRENT MONTH]

how do i  do this in sql
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

SELECT COUNT(*) FROM COMPLETEDVISITS
WHERE date(year,COMPDATE) = datepart(year, getdate())
and date(month,COMPDATE) = datepart(month, getdate())
you need to use between function

SELECT COUNT(*) FROM COMPLETEDVISITS WHERE COMPDATE BETWEEN [FIRST OF THE CURRENT MONTH] AND  [31 OF THE CURRENT MONTH]
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial