What's the difference between these two queries?

This query gives me 10,185

select SUM(int_BenefitEquation) AS total_hours from net_BudgetTools..tbl_DEVELOPERS_Projects where dte_DateOnProduction<='2015-04-07'

This query gives me 9,075

SELECT      SUM(ISNULL(int_BenefitEquation, 0)) AS BenefitHours FROM net_BudgetTools..tbl_DEVELOPERS_Projects
DATEPART(year, dte_DateOnProduction) = '2015'

What's the difference? Basically, I want all of the projects that went into production this year. What's the difference between these two queries that I would wind up with two different figures?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ramachandar NCommented:
First one fetches data till the date "2015-04-07". You are using the date as it is.

Second is the one you have to go for, which pulls the data from the whole year(2015). You are parting the year and joining here.
Top query has this:

This would get April 7 of 2015 and all days before, but also get all years before 2015. Bottom query is only getting those in year 2015.
There is also an isNULL in play on the bottom one.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
Check if the difference are from records with date higher than today:
select SUM(int_BenefitEquation) AS total_hours from net_BudgetTools..tbl_DEVELOPERS_Projects where dte_DateOnProduction>GETDATE()

Open in new window

try something like this:

select SUM(int_BenefitEquation) AS total_hours
from net_BudgetTools..tbl_DEVELOPERS_Projects
where dte_DateOnProduction>='2015-01-01 00:00:00' and
            dte_DateOnProduction<='2015-12-31 11:59:59'
Jim HornMicrosoft SQL Server Data DudeCommented:
<Not an answer, but...>

brucegust - SQL expert PorletPaul's article titled Beware of Between would be an excellent read for your situation.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.