Subject | How to trap conversion error inside SP? |
---|---|
Author | John vd Waeter |
Post date | 2010-05-26T16:37:28Z |
Hi all,
I have this SP that needs to cast a varchar to an integer.
Others fill the table, and the varchar should have a content that is
convertible to an integer, but sometimes the contents of the varchar is
not convertible to an integer because it contains e.g. 'a'.
I know I'm working around a design-problem.
However, is something like this possible inside an SP ?
(in meta delphi language using try... except):
...
try
select first 1 cast(answer as integer)
from answer_table
where .....
into i_answer
except
i_answer = -1
end
IOW, how to trap the conversion-error if answer = 'a' and produce -1 as
a result?
tia!
John
I have this SP that needs to cast a varchar to an integer.
Others fill the table, and the varchar should have a content that is
convertible to an integer, but sometimes the contents of the varchar is
not convertible to an integer because it contains e.g. 'a'.
I know I'm working around a design-problem.
However, is something like this possible inside an SP ?
(in meta delphi language using try... except):
...
try
select first 1 cast(answer as integer)
from answer_table
where .....
into i_answer
except
i_answer = -1
end
IOW, how to trap the conversion-error if answer = 'a' and produce -1 as
a result?
tia!
John