SQL query to return records from only the current month

fcsIT
fcsIT used Ask the Experts™
on
I need to change the DATEADD portion of the following query so it looks at the first day of the current month forward, instead of simply the previous 30 days.

Example, using the query shown below, and today's date of April 17th, I need it to say DATEADD(d,-17,getdate())

How do I write a query that automatically calculates how many days back the first day of the current month is?

select distinct cpid
from results
where eventdate > DATEADD(d,-30,getdate())
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
select distinct cpid
from results
where eventdate > DATEADD(d,-1 * DAY(getdate()) + 1,getdate())
sorry no, it is

select distinct cpid
from results
where eventdate >= DATEADD(d,-1 * DAY(getdate()) + 1,getdate())
or to use the date only and ignore time

select distinct cpid
from results
where eventdate >= DATEADD(d,-1 * DAY(getdate()) + 1,cast(FLOOR(cast(getdate() as float)) as datetime))

Author

Commented:
Perfect, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial