Subject Re: String to Integer
Author Adam
--- In firebird-support@yahoogroups.com, "rogerpullen" <rpullen@...>
wrote:
>
> All - I have a VARCHAR field with values
> that in reality are integers - "1" or "200" etc.
>
> I need to populate an INTEGER field with these
> obviously casting along the way but it does
> not seem to work and also I cannot figure
> out how to trap for conversion errors

Roger,

It is one way or the other. Either they are integers, or not.

If they really are integers, then Cast(MyField as Integer) will do
what you want. If not, you will get an exception.

Of course you could use a PSQL module to select the values one at a
time, cast them as an integer with a when any do to catch and ignore
exceptions.

for
select id, myfield
from mytable
into :id, :myfield
do
begin
update mytable set
myintfield = cast(:myfield as integer)
where id = :id;

when any do
begin
-- ignore any error
end
end

Adam