Error 104: Using the UNION operator

Error 104: Using the UNION operator

Post by Lubor Kolla » Wed, 09 Jun 1999 04:00:00



One question: When you combine all for parts of the union, do you have an
ORDER BY following it all? (the message suggests that yes)

One potential problem is in the derived table definition following the 6th
element in the SELECT list:
(SELECT TOP 1 tblHDpresc.td FROM tblHDPresc WHERE
tblHDPresc.patID=[tblHDrecords].[patID] ORDER BY tblHDPresc.date DESC) AS td

It defines a derived table (from then on you can refer to "td" as a table
inside the query), but you are not referring to it anywhere. This table has
a single column "td" (confusing?) but as is it does not contribute to the
select list. That may be the problem of the ORDER BY mismatch.

Lubor


Quote:> I am converting an access'97 Union query to SQL7. I have broken the union
> query into four parts (stored procs), all of which are working on a stand
> alone basis. When trying to combine the results using the UNION operation,
i
> get the following error:

> Error 104: Order by items must appear in the selected list if the
statement
> contains a Union operator.

> Please find attached a text file that attempts to use union to combine two
> of the four components of my query.

> Any help wrt UNION Queries would be very much appreciated.

> Cheers.