Subject Re: Cast numeric(4,2) as Varchar(20) returns null string
Author robertosmith8
Hi Helen,

Thanks. As you mentioned, there is a logical bug in my code that
caused the variable to remain in the null state.

regards,
roberto

--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...> wrote:
>
> At 11:13 PM 7/06/2008, you wrote:
> >Hi,
> >
> >if X is defined as follows:
> >declare variable X numeric(4,2);
> > or
> >declare variable X numeric(9,4);
> >
> >
> >Why is it that CAST(X AS VARCHAR(20)) returns a NULL string? (for
> >instance X = 5.5, the CAST function returns a NULL string)
>
> CAST() needs a value to operate on. If you declare a variable, it
is null until a value is assigned to it. Null is not a value, it is a
state. There is no such thing as "a null string". CAST(NULL AS
VARCHAR(20)) returns null.
>
> If, for example, you declared as follows (as you can):
>
> declare variable x numeric(9,4) = 5.5;
> declare variable xv varchar(20);
> ...
> ..
> xv = CAST(X AS VARCHAR(20))
>
> you should get '5.5000' returned.
>
> ./heLen
>