Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Trying to use the following and I keep getting a syntax error Select Job.Department, Sum(Job.TotalTicket)From JobGroup By Job.DepartmentWhere Job.SchedDate Between DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0)AND DATEADD(d, DATEDIFF(d, 0, GETDATE()), 1)) I swear I've used this before and it worked just fine to pull data for Today's Date.Ryan A Nelsch
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2012-09-11 : 13:17:58
You have an extra parenthesis and you need to move the GROUP BY after the WHERE clause.:
elect Job.Department,Sum(Job.TotalTicket)From JobWhere Job.SchedDate Between DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0)AND DATEADD(d, DATEDIFF(d, 0, GETDATE()), 1)) Group By Job.Department
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-09-11 : 14:19:57
other small issue is using BETWEEN will cause it include records that got created on midnight next day as wellso if you really want result to be restricted to today much safer way would be
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
rnelsch
Starting Member
31 Posts
Posted - 2012-09-11 : 16:10:28
Ah, thank you.Ryan A Nelsch
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-09-11 : 16:22:35
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/