I'm trying to create a new stored procedure in SQL 2000.The syntax seems ok to me, but I get this message box every time I attempt to save:Title: Microsoft SQL-DMO (ODBC SQLState: 4200)Message: Error 104: ORDER BY items must appear in the select list if the statement contains a UNION operator.Could someone tell me how to fix this?I started by copying an existing query, modified it to only return the Operator field. This worked but returned duplicate operator names, so I modified the "Test_Results" query (last one), and now I can not save.Here is my SQL procedure (not saved):CREATE PROCEDURE AcpReport_OperatorByDates(@DateStart DateTime, @DateEnd DateTime) AS/* Created by Joe Pool for the new ACP Reporter - Returns records ordered by Date_Time */SELECT DISTINCT EI.[FIRSTNAME]+' '+EI.[LASTNAME]+' ('+AP.[OP_ID]+')' AS OperatorFROM ACP_Parts AP LEFT JOIN EmployeeInfo EI ON RTrim(AP.[OP_ID])=RTrim(EI.[NUM])WHERE (@DateStart<[Date_Time]) AND ([Date_Time]<@DateEnd)UNIONSELECT DISTINCT EI.[FIRSTNAME]+' '+EI.[LASTNAME]+' ('+FC.[OP_ID]+')' AS OperatorFROM Final_Check FC LEFT JOIN EmployeeInfo EI ON RTrim(FC.[OP_ID])=RTrim(EI.[NUM])WHERE (@DateStart<[Date_Time]) AND ([Date_Time]<@DateEnd)UNIONSELECT DISTINCT EI.[FIRSTNAME]+' '+EI.[LASTNAME]+' ('+BD.[OP_ID]+')' AS OperatorFROM Box_Data BD INNER JOIN Box_Contents BC ON BD.[Box_Number]=BC.[Box_Number] LEFT JOIN EmployeeInfo EI ON RTrim(BD.[OP_ID])=RTrim(EI.[NUM])WHERE (@DateStart<[Date_Time]) AND ([Date_Time]<@DateEnd)UNIONSELECT DISTINCT CASE WHEN ((SELECT Count(FIRSTNAME) FROM EmployeeInfo WHERE (Replace(RTrim(TR.OP_ID), ' ', ' ')=(RTrim(FirstName)+' '+RTrim(LastName))))>0) THEN (SELECT TOP 1 FIRSTNAME+' '+LASTNAME+' ('+NUM+')' AS Operator FROM EmployeeInfo WHERE (Replace(RTrim(TR.OP_ID), ' ', ' ')=(RTrim(FirstName)+' '+RTrim(LastName))) ORDER BY [COUNT] DESC) ELSE TR.[OP_ID] END AS OperatorFROM Test_Results TRWHERE (@DateStart<[Date_Time]) AND ([Date_Time]<@DateEnd)ORDER BY OperatorGO
Avoid Sears Home Improvement