Query using SubQuery returns nothing

I have the below query/subquery.  The subquery by itself does return data so I know that is working.  However, I simply want a column with the next change, yet when I run it, no rows are returned, just the message Command(s) completed successfully!  But here are my rows?

SELECT  Total_2004_SQ-Total_2003_SQ AS NetChange
      From (SELECT s.BusinessEntityID, SUM(s2004.SalesQuota) AS Total_2004_SQ,SUM(s2003.SalesQuota) As Total_2003_SQ
      FROM Sales.SalesPerson As s
      LEFT OUTER JOIN Sales.SalesPersonQuotaHistory AS s2004
            ON s.BusinessEntityID = s2004.BusinessEntityID AND YEAR(s2004.QuotaDate) = 2004
      LEFT OUTER JOIN Sales.SalesPersonQuotaHistory As s2003
            ON s.BusinessEntityID = s2003.BusinessEntityID AND YEAR(s2003.QuotaDate) = 2003
      GROUP BY s.BusinessEntityID)

This is on a SQL Server 2008 database.

Sandra SmithRetiredAsked:
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.

dsackerContract ERP Admin/ConsultantCommented:
If even one of the left joins are null, your calculation will be null.

Replace your top line as follows:
SELECT  ISNULL(Total_2004_SQ, 0) - ISNULL(Total_2003_SQ, 0) AS NetChange

Open in new window

Sandra SmithRetiredAuthor Commented:
Before I tried your suggestion, I re-ran the query and now I get the message "Incorrect syntax near ')' at line 10, which is the line

      LEFT OUTER JOIN Sales.SalesPersonQuotaHistory As s2003

this is in the subquery, which does return results by itself so now I am in a quandary.  I made your suggested changes and still get this same error.

dsackerContract ERP Admin/ConsultantCommented:
Right after you close the subquery with an ending paranthesis, give it an alias.

GROUP BY s.BusinessEntityID)  AS myResult

Open in new window

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
Sandra SmithRetiredAuthor Commented:
That was it!  So, I need to remember to alias my subqueries.  Thank you.

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 Development

From novice to tech pro — start learning today.