Question : Issue with performance of a SQL query

I have a SQL Query that doesn't perform well.  It takes about 20 minutes to run the attached query and I feel that it could probably run faster, but I'm not exactly sure how to accomplish that.  Can someone give some suggest on what I can do to increase performance?  If it includes creating view or indexes, please include the SQL query to do so as I have never created either.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
SELECT e.EmpName Timekeeper, Sum(f.FSPWorkedHrsEntered) [Hrs Worked], Sum(f.FSPNonBilHrsEntered) [NonBillable Hrs], Sum(f.FSPBilHrsEntered) [Billable Hrs],
  Round((Sum(f.FSPBilHrsEntered) / 12) * 12, 2) [Annualized Billable Hrs], Sum(f.FSPHrsBilled) [Hrs Billed], Sum(f.FSPFeeBldActualAmt) [Fees Billed],
  Round(Sum(f.FSPFeeBldActualAmt) / Sum(f.FSPHrsBilled), 2) [Avg Billed Rate], Sum(f.FSPFeeReceived) [Fees Received], u.[Unbilled Amount], e.Goal, (((e.Percent1 * 11192186.41) / 1000000) +
  ((e.Percent2 * 0) / 1000000) + ((e.Percent3 * 0) / 1000000) + ((e.Percent4 * 0) / 1000000)) [Taxable Income], ((100000 / 12) * 12) Cost,
  (Sum(f.FSPFeeBldActualAmt) - (((e.Percent1 * 11192186.41) / 1000000) + ((e.Percent2 * 0) / 1000000) + ((e.Percent3 * 0) / 1000000) + ((e.Percent4 * 0) / 1000000)) - ((100000 /
  12) * 12)) [Profit/Loss]
FROM (SELECT e1.EmpSysNbr Timekeeper, Sum(u1.UTAmount) [Unbilled Amount]
    FROM dbo.UnbilledTime u1
      INNER JOIN dbo.Employee e1 ON u1.UTTkpr = e1.EmpSysNbr
    GROUP BY e1.EmpSysNbr) u
    INNER JOIN dbo.Employee e ON u.Timekeeper = e.EmpSysNbr
    INNER JOIN dbo.FeeSumByPrd f ON e.EmpSysNbr = f.FSPTkpr
  WHERE f.FSPPrdYear = 2009 AND f.FSPPrdNbr BETWEEN 1 AND 12 AND e.EmpSysNbr NOT IN (103, 109, 56, 68, 88, 105, 44, 34, 174, 147, 46, 29, 37, 201, 148, 69, 36, 45)
    AND e.EmpPrsTyp = '01'
  GROUP BY e.EmpName, u.[Unbilled Amount], e.Goal, e.EmpPrsTyp, e.Percent1, e.Percent2, e.Percent3, e.Percent4
    HAVING Sum(f.FSPWorkedHrsEntered) > 0
    ORDER BY e.EmpName, e.EmpPrsTyp

Answer : Issue with performance of a SQL query

Hello TPBPIT,

Generally speaking, you want to have indexes on any columns used in joins, and as WHERE criteria.  Also,
Try not to use IN unless you have to: using IN for e.EmpSysNbr may interfere with SQL Server leveraging
an index on that column, thus resulting in a full table scan (bad!).

Regards,

Patrick
Random Solutions  
 
programming4us programming4us