community.borland.com

Article #25794: How to determine the datatype for a constant?

Problem:
There is no documentation on what is the datatype for a constant.  When using constant in 
an union statement where the columns selected must have compatible datatype, 
the statement would fail.  

Solution:
The datatype for constant is determined dynamically by the engine.  
For example, if you pass "far", the engine will pick it up as char(3).  
And if you use 0, the engine will pick it up as integer.  It's important to 
note that integer is the datatype used for numbers.  If mismatch datatype 
is detected, one can cast this datatype to the compatible dattype.  For example,

create table table1 (f1 smallint, f2 varchar(5));

Failing statement:
------------------
select 0, "fun" from table1 union select f1, f2 from table1;


Correct statement:
------------------
select cast(0 as smallint), cast("fun" as varchar(5)) from table1 union select f1, f2 from table1;


Last Modified: 28-SEP-00