Subject Re: [firebird-support] UNION Problems
Author Helen Borrie
At 01:56 PM 17/01/2005 +0000, you wrote:

>I am having problems using the union operator on two tables. Could
>somebody point out my mistake.

Yup. And don't believe everything Martijn says. He gets like this when
someone cuts off his intravenous chocolate. :-)

>Below is the SQL code.
>
>
>SELECT CAST LrgAddrData
>FROM LargeAddress
>WHERE WPVBSQ < 20
>UNION ALL
>SELECT CAST (SmllAddrData AS CHAR)
>FROM SmallAddress
>WHERE WPVBSQ < 20

OK, the line that is causing the 'invalid token' exception is right at the
beginning. The syntax of the CAST expression is wrong. It should be

SELECT CAST(lrgAddrData AS VARCHAR(10) )

But you will (potentially) encounter another exception when you get to the
second SELECT (an overflow exception).

The overflow occurs if the column contains a number larger than 9 (the
largest integer that can be cast as CHAR). Play safe and cast this as
VARCHAR(10) as well.

As a rule, cast date types as char(n) and numbers as varchar(n).

./hb