Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL that only looks at current month data?

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2012-07-31 : 10:29:35
Hi guys,

I am looking for a SQL statement that only gets data for the current month a query is run. If the query is run next month, it should only return data for that month.

Just for example purposes, the field to use is job.job_entry_date.

If anyone has a statement they could share I'd appreciate it

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 10:31:33
just add a condition like

..
WHERE job.job_entry_date >=DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
AND job.job_entry_date < DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 10:32:32
refer this for explanation


http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2012-07-31 : 10:47:07
Brilliant, thanks for that Visakh!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-31 : 10:50:53
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -