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

  • Hello,

    I have the following query and I'm getting the following error.

    Msg 8120, Level 16, State 1, Line 3

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

    I have searched this forum where similar questions have been asked but I cant resolve the error.

    http://www.sqlservercentral.com/Forums/Topic667707-1291-1.aspx and http://www.sqlservercentral.com/Forums/Topic1322969-392-1.aspx

    use MICE

    select

    b.School_Year,

    b.School_Code,b.School_Name,b.Village_Name,b.Block_Name,b.Cluster_Name,b.District_Name,b.Pin_Code,

    F.Blackboard,F.Book_Bank,F.Books_in_library,F.Boundary_Wall,F.Building_Status,F.Classrooms_in_Good_Condition,

    F.Classrooms_require_major_repair,F.Classrooms_require_minor_repair,F.Computer_Aided_Learning_Lab,

    F.Days_involved_in_non_tch_assgn,F.Drinking_Water,F.Electricity,F.Female_Tch,F.Graduate_Teachers,

    F.Head_Teacher,F.Kitchen_Devices_Grant,F.Library_YN,F.Male_Tch,F.Medical_Checkup,F.No_of_Computers,

    F.NoResp_Tch,F.Other_rooms_in_Good_Cond,F.Other_rooms_need_major_rep,F.Other_rooms_need_minor_rep,

    F.PlayGround,F.Ramps,F.Seperate_room_for_HeadMaster,F.Status_of_MDM,F.Tch_with_professional_Qualification,

    F.Teachers_involved_in_non_tch_assgn,F.Toilet_Boys,F.Toilet_Common,F.Toilet_Girls,F.Tot_Clrooms,

    E.C5_Appeared_Boys,E.C5_Appeared_Girls,E.C5_Passed_Boys,E.C5_Passed_Girls,

    E.C5_Passed_with_more_than_60_Boys,E.C5_Passed_with_more_than_60_Girls,

    E.C7_Appeared_Boys,E.C7_Appeared_Girls,E.C7_Passed_Boys,E.C7_Passed_Girls,

    E.C7_Passed_with_more_than_60_Boys,E.C7_Passed_with_more_than_60_Girls,

    E.Class1_OBC_Enr_Boys,E.Class1_OBC_Enr_Girls,

    E.Class1_SC_Enr_Boys,E.Class1_SC_Enr_Girls,

    E.Class1_ST_Enr_Boys,E.Class1_ST_Enr_Girls,

    E.Class1_Total_Enr_Boys,E.Class1_Total_Enr_Girls,

    E.Class2_OBC_Enr_Boys,E.Class2_OBC_Enr_Girls,

    E.Class2_SC_Enr_Boys,E.Class2_SC_Enr_Girls,

    E.Class2_ST_Enr_Boys,E.Class2_ST_Enr_Girls,

    e.Class2_Total_Enr_Boys,e.Class2_Total_Enr_Girls,

    e.Class3_OBC_Enr_Boys,e.Class3_OBC_Enr_Girls,

    e.Class3_SC_Enr_Boys,e.Class3_SC_Enr_Girls,

    e.Class3_ST_Enr_Boys,e.Class3_ST_Enr_Girls,

    e.Class3_Total_Enr_Boys,e.Class3_Total_Enr_Girls,

    e.Class4_OBC_Enr_Boys,e.Class4_OBC_Enr_Girls,

    e.Class4_SC_Enr_Boys,e.Class4_SC_Enr_Girls,

    e.Class4_ST_Enr_Boys,e.Class4_ST_Enr_Girls,

    e.Class4_Total_Enr_Boys,e.Class4_Total_Enr_Girls,

    E.Class5_OBC_Enr_Boys,E.Class5_OBC_Enr_Girls,

    E.Class5_SC_Enr_Boys,E.Class5_SC_Enr_Girls,

    E.Class5_ST_Enr_Boys,E.Class5_ST_Enr_Girls,

    E.Class5_Total_Enr_Boys,E.Class5_Total_Enr_Girls,

    E.Class6_OBC_Enr_Boys,E.Class6_OBC_Enr_Girls,

    E.Class6_SC_Enr_Boys,E.Class6_SC_Enr_Girls,

    E.Class6_ST_Enr_Boys,E.Class6_ST_Enr_Girls,

    e.Class6_Total_Enr_Boys,e.Class6_Total_Enr_Girls,

    e.Class7_OBC_Enr_Boys,e.Class7_OBC_Enr_Girls,

    e.Class7_SC_Enr_Boys,e.Class7_SC_Enr_Girls,

    e.Class7_ST_Enr_Boys,e.Class7_ST_Enr_Girls,

    e.Class7_Total_Enr_Boys,e.Class7_Total_Enr_Girls,

    e.Class8_OBC_Enr_Boys,e.Class8_OBC_Enr_Girls,

    e.Class8_SC_Enr_Boys,e.Class8_SC_Enr_Girls,

    e.Class8_ST_Enr_Boys,e.Class8_ST_Enr_Girls,

    e.Class8_Total_Enr_Boys,e.Class8_Total_Enr_Girls,

    e.Disabled_C1_Boys,e.Disabled_C1_Girls,

    e.Disabled_C2_Boys,e.Disabled_C2_Girls,

    e.Disabled_C3_Boys,e.Disabled_C3_Girls,

    e.Disabled_C4_Boys,e.Disabled_C4_Girls,

    e.Disabled_C5_Boys,e.Disabled_C5_Girls,

    e.Disabled_C6_Boys,e.Disabled_C6_Girls,

    e.Disabled_C7_Boys,e.Disabled_C7_Girls,

    e.Disabled_C8_Boys,e.Disabled_C8_Girls,

    e.Repeaters_C1_Boys,e.Repeaters_C1_Girls,

    e.Repeaters_C2_Boys,e.Repeaters_C2_Girls,

    e.Repeaters_C3_Boys,e.Repeaters_C3_Girls,

    e.Repeaters_C4_Boys,e.Repeaters_C4_Girls,

    e.Repeaters_C5_Boys,e.Repeaters_C5_Girls,

    e.Repeaters_C6_Boys,e.Repeaters_C6_Girls,

    AVG(e.Class1_OBC_Enr_Boys+e.Class1_SC_Enr_Boys+e.Class1_ST_Enr_Boys+e.Class1_Total_Enr_Boys+

    e.Class2_OBC_Enr_Boys+e.Class2_SC_Enr_Boys+Class2_ST_Enr_Boys+Class2_Total_Enr_Boys+

    e.Class3_OBC_Enr_Boys+Class3_SC_Enr_Boys+Class3_ST_Enr_Boys+Class3_Total_Enr_Boys+

    e.Class4_OBC_Enr_Boys+e.Class4_SC_Enr_Boys+e.Class4_ST_Enr_Boys+e.Class4_Total_Enr_Boys+

    e.Class5_OBC_Enr_Boys+e.Class5_SC_Enr_Boys+e.Class1_ST_Enr_Boys+e.Class5_Total_Enr_Boys+

    e.Class6_OBC_Enr_Boys+e.Class6_SC_Enr_Boys+e.Class6_ST_Enr_Boys+e.Class6_Total_Enr_Boys+

    e.Class7_OBC_Enr_Boys+e.Class7_SC_Enr_Boys+e.Class7_ST_Enr_Boys+e.Class7_Total_Enr_Boys+

    e.Class8_OBC_Enr_Boys+e.Class8_SC_Enr_Boys+e.Class8_ST_Enr_Boys+e.Class8_Total_Enr_Boys+

    e.Disabled_C1_Boys+e.Disabled_C2_Boys+e.Disabled_C3_Boys++e.Disabled_C4_Boys++e.Disabled_C5_Boys+

    e.Disabled_C6_Boys+e.Disabled_C7_Boys+e.Disabled_C8_Boys+

    e.C5_Appeared_Boys+e.C5_Passed_with_more_than_60_Boys+e.C7_Appeared_Boys+

    e.C7_Passed_with_more_than_60_Boys

    )as Avg_Tot_Enr_Boys,

    AVG(e.Class1_OBC_Enr_Girls+e.Class1_SC_Enr_Girls+e.Class1_ST_Enr_Girls+e.Class1_Total_Enr_Girls+

    e.Class2_OBC_Enr_Girls+e.Class2_SC_Enr_Girls+Class2_ST_Enr_Girls+Class2_Total_Enr_Girls+

    e.Class3_OBC_Enr_Girls+Class3_SC_Enr_Girls+Class3_ST_Enr_Girls+Class3_Total_Enr_Girls+

    e.Class4_OBC_Enr_Girls+e.Class4_SC_Enr_Girls+e.Class4_ST_Enr_Girls+e.Class4_Total_Enr_Girls+

    e.Class5_OBC_Enr_Girls+e.Class5_SC_Enr_Girls+e.Class1_ST_Enr_Girls+e.Class5_Total_Enr_Girls+

    e.Class6_OBC_Enr_Boys+e.Class6_SC_Enr_Girls+e.Class6_ST_Enr_Girls+e.Class6_Total_Enr_Girls+

    e.Class7_OBC_Enr_Girls+e.Class7_SC_Enr_Girls+e.Class7_ST_Enr_Girls+e.Class7_Total_Enr_Girls+

    e.Class8_OBC_Enr_Girls+e.Class8_SC_Enr_Girls+e.Class8_ST_Enr_Girls+e.Class8_Total_Enr_Girls+

    e.Disabled_C1_Girls+e.Disabled_C2_Girls+e.Disabled_C3_Girls+e.Disabled_C4_Girls+e.Disabled_C5_Girls+

    e.Disabled_C6_Girls+e.Disabled_C7_Girls+e.Disabled_C8_Girls+

    e.C5_Appeared_Girls+e.C5_Passed_with_more_than_60_Girls+e.C7_Appeared_Girls+

    e.C7_Passed_with_more_than_60_Girls

    )as Avg_Tot_Enr_Girls,

    AVG(e.Repeaters_C1_Boys+e.Repeaters_C2_Boys+e.Repeaters_C3_Boys+e.Repeaters_C4_Boys

    +e.Repeaters_C5_Boys+e.Repeaters_C6_Boys+e.Repeaters_C7_Boys+e.Repeaters_C8_Boys) as Avg_Repeater_Boys,

    AVG(e.Repeaters_C1_Girls+e.Repeaters_C2_Girls+e.Repeaters_C3_Girls+e.Repeaters_C4_Girls

    +e.Repeaters_C5_Girls+e.Repeaters_C6_Girls+e.Repeaters_C7_Girls+e.Repeaters_C8_Girls) as Avg_Repeater_Girls,

    g.Distance_BRC,g.Distance_CRC,g.Funds_from_students_Expnd,g.Funds_from_students_Recd,

    g.Highest_Class,g.Lowest_Class,g.Medium_of_Instruction,g.No_of_Working_Days,g.No_of_Acad_Inspection,

    g.Pre_Pry_Students,g.Pre_Pry_Teachers,g.Pre_Pry_YN,g.Residential_Sch_Type,g.Residential_Sch_YN,

    g.Rural_Urban,g.Sch_Category,g.Sch_Management,g.School_Dev_Grant_Expnd,g.School_Dev_Grant_Recd,

    g.School_Type,g.Shift_School_YN,

    t.DaysInvolvd,t.GradAbove,t.HeadTch,t.Tch_Female,t.Tch_Male,t.Tch_NR

    into School_Perform_Data_2020

    from Basic_Data b

    INNER JOIN ER_Data e ON b.School_Code = e.School_Code

    INNER JOIN FacilityData f ON b.School_Code = f.School_Code

    INNER JOIN GeneralData g ON b.School_Code = g.School_Code

    INNER JOIN TeacherData t ON b.School_Code = t.School_Code

    WHERE E.acyear = '2010-11'

    Group by e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code

    Any help will be appreciated.

    Thanks

  • Dear Ashish,

    As the error suggest School_Year is not a part of either a aggregate function or a group by clause.

    What you need to do is ad School_Year in the list of columns on which you are grouping the outcome of your query.

    Group by

    e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code,

    b.School_Year

    Hope this helps...!!

    Regards

    Shafat Husain

    Regards,
    Shafat Husain
    🙂
    And Your Lord Never Forgets...!! (64:19 -- Quran)

  • Dear Shafat,

    Thanks for your reply. But its not working.

    When I add b.School_Year I get another error message that says b.School_code is because it is not contained in either an aggregate function or the GROUP BY clause. So if I add b.School_Code in the Group by clause the error jumps to the next attribute in the table...

    My understanding was that all those variables that are not used in the aggregate function in my case the AVG function are to be listed in the Group by clause... Which I did but I dont know why I'm getting this error message.

    Please help.

  • Quick thought, switch from group by to window function with output de-duplication

    😎

    use MICE

    SELECT

    *

    into School_Perform_Data_2020

    FROM

    (

    select

    ROW_NUMBER() OVER

    (

    PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code

    ORDER BY (SELECT NULL)

    ) AS DD_RID

    b.School_Year,

    b.School_Code,b.School_Name,b.Village_Name,b.Block_Name,b.Cluster_Name,b.District_Name,b.Pin_Code,

    F.Blackboard,F.Book_Bank,F.Books_in_library,F.Boundary_Wall,F.Building_Status,F.Classrooms_in_Good_Condition,

    F.Classrooms_require_major_repair,F.Classrooms_require_minor_repair,F.Computer_Aided_Learning_Lab,

    F.Days_involved_in_non_tch_assgn,F.Drinking_Water,F.Electricity,F.Female_Tch,F.Graduate_Teachers,

    F.Head_Teacher,F.Kitchen_Devices_Grant,F.Library_YN,F.Male_Tch,F.Medical_Checkup,F.No_of_Computers,

    F.NoResp_Tch,F.Other_rooms_in_Good_Cond,F.Other_rooms_need_major_rep,F.Other_rooms_need_minor_rep,

    F.PlayGround,F.Ramps,F.Seperate_room_for_HeadMaster,F.Status_of_MDM,F.Tch_with_professional_Qualification,

    F.Teachers_involved_in_non_tch_assgn,F.Toilet_Boys,F.Toilet_Common,F.Toilet_Girls,F.Tot_Clrooms,

    E.C5_Appeared_Boys,E.C5_Appeared_Girls,E.C5_Passed_Boys,E.C5_Passed_Girls,

    E.C5_Passed_with_more_than_60_Boys,E.C5_Passed_with_more_than_60_Girls,

    E.C7_Appeared_Boys,E.C7_Appeared_Girls,E.C7_Passed_Boys,E.C7_Passed_Girls,

    E.C7_Passed_with_more_than_60_Boys,E.C7_Passed_with_more_than_60_Girls,

    E.Class1_OBC_Enr_Boys,E.Class1_OBC_Enr_Girls,

    E.Class1_SC_Enr_Boys,E.Class1_SC_Enr_Girls,

    E.Class1_ST_Enr_Boys,E.Class1_ST_Enr_Girls,

    E.Class1_Total_Enr_Boys,E.Class1_Total_Enr_Girls,

    E.Class2_OBC_Enr_Boys,E.Class2_OBC_Enr_Girls,

    E.Class2_SC_Enr_Boys,E.Class2_SC_Enr_Girls,

    E.Class2_ST_Enr_Boys,E.Class2_ST_Enr_Girls,

    e.Class2_Total_Enr_Boys,e.Class2_Total_Enr_Girls,

    e.Class3_OBC_Enr_Boys,e.Class3_OBC_Enr_Girls,

    e.Class3_SC_Enr_Boys,e.Class3_SC_Enr_Girls,

    e.Class3_ST_Enr_Boys,e.Class3_ST_Enr_Girls,

    e.Class3_Total_Enr_Boys,e.Class3_Total_Enr_Girls,

    e.Class4_OBC_Enr_Boys,e.Class4_OBC_Enr_Girls,

    e.Class4_SC_Enr_Boys,e.Class4_SC_Enr_Girls,

    e.Class4_ST_Enr_Boys,e.Class4_ST_Enr_Girls,

    e.Class4_Total_Enr_Boys,e.Class4_Total_Enr_Girls,

    E.Class5_OBC_Enr_Boys,E.Class5_OBC_Enr_Girls,

    E.Class5_SC_Enr_Boys,E.Class5_SC_Enr_Girls,

    E.Class5_ST_Enr_Boys,E.Class5_ST_Enr_Girls,

    E.Class5_Total_Enr_Boys,E.Class5_Total_Enr_Girls,

    E.Class6_OBC_Enr_Boys,E.Class6_OBC_Enr_Girls,

    E.Class6_SC_Enr_Boys,E.Class6_SC_Enr_Girls,

    E.Class6_ST_Enr_Boys,E.Class6_ST_Enr_Girls,

    e.Class6_Total_Enr_Boys,e.Class6_Total_Enr_Girls,

    e.Class7_OBC_Enr_Boys,e.Class7_OBC_Enr_Girls,

    e.Class7_SC_Enr_Boys,e.Class7_SC_Enr_Girls,

    e.Class7_ST_Enr_Boys,e.Class7_ST_Enr_Girls,

    e.Class7_Total_Enr_Boys,e.Class7_Total_Enr_Girls,

    e.Class8_OBC_Enr_Boys,e.Class8_OBC_Enr_Girls,

    e.Class8_SC_Enr_Boys,e.Class8_SC_Enr_Girls,

    e.Class8_ST_Enr_Boys,e.Class8_ST_Enr_Girls,

    e.Class8_Total_Enr_Boys,e.Class8_Total_Enr_Girls,

    e.Disabled_C1_Boys,e.Disabled_C1_Girls,

    e.Disabled_C2_Boys,e.Disabled_C2_Girls,

    e.Disabled_C3_Boys,e.Disabled_C3_Girls,

    e.Disabled_C4_Boys,e.Disabled_C4_Girls,

    e.Disabled_C5_Boys,e.Disabled_C5_Girls,

    e.Disabled_C6_Boys,e.Disabled_C6_Girls,

    e.Disabled_C7_Boys,e.Disabled_C7_Girls,

    e.Disabled_C8_Boys,e.Disabled_C8_Girls,

    e.Repeaters_C1_Boys,e.Repeaters_C1_Girls,

    e.Repeaters_C2_Boys,e.Repeaters_C2_Girls,

    e.Repeaters_C3_Boys,e.Repeaters_C3_Girls,

    e.Repeaters_C4_Boys,e.Repeaters_C4_Girls,

    e.Repeaters_C5_Boys,e.Repeaters_C5_Girls,

    e.Repeaters_C6_Boys,e.Repeaters_C6_Girls,

    AVG(e.Class1_OBC_Enr_Boys+e.Class1_SC_Enr_Boys+e.Class1_ST_Enr_Boys+e.Class1_Total_Enr_Boys+

    e.Class2_OBC_Enr_Boys+e.Class2_SC_Enr_Boys+Class2_ST_Enr_Boys+Class2_Total_Enr_Boys+

    e.Class3_OBC_Enr_Boys+Class3_SC_Enr_Boys+Class3_ST_Enr_Boys+Class3_Total_Enr_Boys+

    e.Class4_OBC_Enr_Boys+e.Class4_SC_Enr_Boys+e.Class4_ST_Enr_Boys+e.Class4_Total_Enr_Boys+

    e.Class5_OBC_Enr_Boys+e.Class5_SC_Enr_Boys+e.Class1_ST_Enr_Boys+e.Class5_Total_Enr_Boys+

    e.Class6_OBC_Enr_Boys+e.Class6_SC_Enr_Boys+e.Class6_ST_Enr_Boys+e.Class6_Total_Enr_Boys+

    e.Class7_OBC_Enr_Boys+e.Class7_SC_Enr_Boys+e.Class7_ST_Enr_Boys+e.Class7_Total_Enr_Boys+

    e.Class8_OBC_Enr_Boys+e.Class8_SC_Enr_Boys+e.Class8_ST_Enr_Boys+e.Class8_Total_Enr_Boys+

    e.Disabled_C1_Boys+e.Disabled_C2_Boys+e.Disabled_C3_Boys++e.Disabled_C4_Boys++e.Disabled_C5_Boys+

    e.Disabled_C6_Boys+e.Disabled_C7_Boys+e.Disabled_C8_Boys+

    e.C5_Appeared_Boys+e.C5_Passed_with_more_than_60_Boys+e.C7_Appeared_Boys+

    e.C7_Passed_with_more_than_60_Boys

    ) OVER (PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code) as Avg_Tot_Enr_Boys,

    AVG(e.Class1_OBC_Enr_Girls+e.Class1_SC_Enr_Girls+e.Class1_ST_Enr_Girls+e.Class1_Total_Enr_Girls+

    e.Class2_OBC_Enr_Girls+e.Class2_SC_Enr_Girls+Class2_ST_Enr_Girls+Class2_Total_Enr_Girls+

    e.Class3_OBC_Enr_Girls+Class3_SC_Enr_Girls+Class3_ST_Enr_Girls+Class3_Total_Enr_Girls+

    e.Class4_OBC_Enr_Girls+e.Class4_SC_Enr_Girls+e.Class4_ST_Enr_Girls+e.Class4_Total_Enr_Girls+

    e.Class5_OBC_Enr_Girls+e.Class5_SC_Enr_Girls+e.Class1_ST_Enr_Girls+e.Class5_Total_Enr_Girls+

    e.Class6_OBC_Enr_Boys+e.Class6_SC_Enr_Girls+e.Class6_ST_Enr_Girls+e.Class6_Total_Enr_Girls+

    e.Class7_OBC_Enr_Girls+e.Class7_SC_Enr_Girls+e.Class7_ST_Enr_Girls+e.Class7_Total_Enr_Girls+

    e.Class8_OBC_Enr_Girls+e.Class8_SC_Enr_Girls+e.Class8_ST_Enr_Girls+e.Class8_Total_Enr_Girls+

    e.Disabled_C1_Girls+e.Disabled_C2_Girls+e.Disabled_C3_Girls+e.Disabled_C4_Girls+e.Disabled_C5_Girls+

    e.Disabled_C6_Girls+e.Disabled_C7_Girls+e.Disabled_C8_Girls+

    e.C5_Appeared_Girls+e.C5_Passed_with_more_than_60_Girls+e.C7_Appeared_Girls+

    e.C7_Passed_with_more_than_60_Girls

    ) OVER (PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code) as Avg_Tot_Enr_Girls,

    AVG(e.Repeaters_C1_Boys+e.Repeaters_C2_Boys+e.Repeaters_C3_Boys+e.Repeaters_C4_Boys

    +e.Repeaters_C5_Boys+e.Repeaters_C6_Boys+e.Repeaters_C7_Boys+e.Repeaters_C8_Boys) OVER (PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code) as Avg_Repeater_Boys,

    AVG(e.Repeaters_C1_Girls+e.Repeaters_C2_Girls+e.Repeaters_C3_Girls+e.Repeaters_C4_Girls

    +e.Repeaters_C5_Girls+e.Repeaters_C6_Girls+e.Repeaters_C7_Girls+e.Repeaters_C8_Girls) OVER (PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code) as Avg_Repeater_Girls,

    g.Distance_BRC,g.Distance_CRC,g.Funds_from_students_Expnd,g.Funds_from_students_Recd,

    g.Highest_Class,g.Lowest_Class,g.Medium_of_Instruction,g.No_of_Working_Days,g.No_of_Acad_Inspection,

    g.Pre_Pry_Students,g.Pre_Pry_Teachers,g.Pre_Pry_YN,g.Residential_Sch_Type,g.Residential_Sch_YN,

    g.Rural_Urban,g.Sch_Category,g.Sch_Management,g.School_Dev_Grant_Expnd,g.School_Dev_Grant_Recd,

    g.School_Type,g.Shift_School_YN,

    t.DaysInvolvd,t.GradAbove,t.HeadTch,t.Tch_Female,t.Tch_Male,t.Tch_NR

    from Basic_Data b

    INNER JOIN ER_Data e ON b.School_Code = e.School_Code

    INNER JOIN FacilityData f ON b.School_Code = f.School_Code

    INNER JOIN GeneralData g ON b.School_Code = g.School_Code

    INNER JOIN TeacherData t ON b.School_Code = t.School_Code

    WHERE E.acyear = '2010-11'

    ) AS X

    WHERE X.DD_RID = 1;

  • Thanks Eirikur for your response.

    But I'm greeted with the following error on executing the query you posted.

    Msg 102, Level 15, State 1, Line 13

    Incorrect syntax near 'b'.

    The error i get is apparently at this location

    use MICE

    SELECT

    *

    into School_Perform_Data_2020

    FROM

    (

    select

    ROW_NUMBER() OVER

    (

    PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code

    ORDER BY (SELECT NULL)

    ) AS DD_RID

    b.School_Year, ----> here it doesnt recognise the object b.

  • Might I suggest breaking you query down to start with a few columns to get the logic then add columns you need.

    I have even added columns a few at a time if adding all causes problems.

  • Ashish Dutt (12/11/2014)


    Thanks Eirikur for your response.

    But I'm greeted with the following error on executing the query you posted.

    Msg 102, Level 15, State 1, Line 13

    Incorrect syntax near 'b'.

    The error i get is apparently at this location

    use MICE

    SELECT

    *

    into School_Perform_Data_2020

    FROM

    (

    select

    ROW_NUMBER() OVER

    (

    PARTITION BY e.School_Code,f.acyear,f.FcID,f.School_code,e.erID,g.acyear,g.GenID,t.acyear,t.School_Code

    ORDER BY (SELECT NULL)

    ) AS DD_RID

    b.School_Year, ----> here it doesnt recognise the object b.

    Missing comma

    😎

Viewing 7 posts - 1 through 6 (of 6 total)

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