2191 Invalid Data Type

Advantage Error Guide

Problem: The data type of an expression in the SQL statement is not valid in the specified context.

Solution: Use Cast() or Convert() function to force the expression into the required type.

 

Note: In version 8.0 and earlier releases, the error 2191 means "UNION statement can only be ordered by ordinal number". The problem and solution for this error are below.

Problem: The combined result set of the UNION statement can be ORDER BY ordinal numbers only. Individual queries in the UNION statement cannot be sorted with the ORDER BY clause. For example, "SELECT lastname, firstname FROM table1 UNION SELECT lastname, firstname FROM table2 ORDER BY lastname" is not valid because the ORDER BY is not specified with ordinal number.

Solution: Adjust the ORDER BY clause in the UNION statement to use ordinal number columns.