We help IT Professionals succeed at work.

SQL Query help

127 Views
Last Modified: 2017-04-05
I have this query pulling from two tables. It essentially sums the column of a bunch of records then adds some more relevant data where the field EMPLID matches

SELECT        TOP (100) PERCENT t1.FULLNAME, t2.TOTAL_HOURS, t2.EMPLID, t1.MGRID, t2.FiscalYear, t1.VPID
FROM            myDB.dbo.USERSS AS t1 INNER JOIN
                             (SELECT        EMPLID, SUM(Hours) AS TOTAL_HOURS, FiscalYear
                               FROM            dbo.REQUESTS
                               GROUP BY EMPLID, FiscalYear) AS t2 ON t2.EMPLID COLLATE Latin1_General_BIN = t1.EMPLID
WHERE        (t1.DELETED = 'N')

Open in new window


Is there a way for me to pull the same data but also have a record for each entry from the USERS table where there isn't anything found for that record's EMPLID in the REQUESTS table, and just set the SUM of TOTAL_HOURS to 0.00?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
Is there a way for me to pull the same data but also have a record for each entry from the USERS table where there isn't anything found for that record's EMPLID in the REQUESTS table, and just set the SUM of TOTAL_HOURS to 0.00?
yes, try use left join instead of inner join.
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks Ryan!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions