SQL Syntax question -

  • Hi All:

    I have this SQL statement that is not working and I'm not sure what I'm doing wrong

    SELECT A.Incident_Id AS Incident_Id,

    C.Task_Id as Task_Id,

    SUM(B.Billing_Time) AS Incident_Bill,

    SUM(B.Absorbed_Time) AS Incident_Abs,

    SUM(B.Actual_Time) AS Incident_Actual

    -- C.Task_Name

    FROM Incident as A

    Left outer join Inc_History as B

    on A.Incident_Id = B.Incident_Id

    left outer join task as C

    on A.Incident_Id = C.Entity_ID

    GROUP BY A.Incident_Id

    Please help,

    Thanks

    Bill

  • I forgot to supply the ERROR message

    Column 'C.Task_Id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    Thanks

    Bill

  • When you use the GROUP BY clause, all columns not included in the GROUP BY must be aggregate values.  GROUP BY tells SQL Server that you want to display only one row for each 'group' as defined in your GROUP BY clause.  To do this, you must be able to combine or summarize the data so that the result set has one row for each group.  Your query should work fine if you remove the Task_ID column from your SELECT or if you GROUP BY Incendent_ID and Task_ID. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply