I have the following two SQL Statements, each returns five columns of the same type and, by themselves, each runs perfectly OK.
SELECT GetDate() as [Date], 'Category' as [Type], '' as [Field],
CATEGORIES.CATEGORYCODE as [Code], COUNT(CONTACTS.CATEGORYCODE) as [Count]
FROM CATEGORIES LEFT OUTER JOIN CONTACTS
GROUP BY CATEGORIES.CATEGORYCODE
SELECT GetDate() as [Date], 'Attribute' as [Type], ST R(C.ATTRIBUTETYPEID) as [Field],
C.ATTRIBUTECODE as [Code], COUNT(A.CONTACTID) AS [Count]
FROM ATTRIBUTECODES C LEFT OUTER JOIN ATTRIBUTES A
ON C.ATTRIBUTETYPEID = A.ATTRIBUTETYPEID
AND C.ATTRIBUTECODE = A.ATTRIBUTECODE
GROUP BY C.ATTRIBUTETYPEID, C.ATTRIBUTECODE
ORDER BY C.ATTRIBUTETYPEID, C.ATTRIBUTECODE
However, when I insert a UNION ALL clause between the two SELECT statements, I get the following error:
The column prefix 'C' does not match with a table name or alias name used in the query.
What's it going on about?
URGENT : 500 POINTS