Home Forums SQL Server 2005 SQL Server Newbies LEFT JOIN not returning anticipated results from Left table in query RE: LEFT JOIN not returning anticipated results from Left table in query

  • Would this give you the correct result?

    SELECT

    Users.Department as Dept,

    CaseTypes.Description as Case_Type,

    Users.Code as FE,

    COUNT(Matters.FeeEarnerRef) as No_of_Matters,

    ISNULL(SUM(Usr_Int1.Estimated_total_fee),0) as Fee_Estimate

    FROM

    ((Users LEFT JOIN Matters ON Users.Code = Matters.FeeEarnerRef and (Matters.Created >= GetDate() - 7 AND Matters.Created <= GetDate())

    INNER JOIN CaseTypes ON Matters.CaseTypeRef = CaseTypes.Code)

    LEFT --This is the only change

    JOIN Usr_Int1 ON (Matters.Number = Usr_Int1.MatterNo) AND (Matters.EntityRef = Usr_Int1.EntityRef))

    WHERE

    ((usertyperef =1) or (usertyperef = 2))

    GROUP BY

    users.code, usertyperef, users.department, casetypes.description, users.department, casetyperef, users.feeearner

    ORDER BY

    users.department, casetyperef, users.code;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2