Skip to content
Advertisement

Convert CHAR to int in SQL results in error

I’m using Toad Data Point and am having an issue converting a Column. I’m trying to convert a Column called Rep which contains Char(2) into an integer. The table looks like this:

I’ve tried the following:

I tried CAST(Rep as INT) as well and both give me the error Sybase Database Error: Data Exception -date type conversion is not possible.

Thanks

Advertisement

Answer

In Sybase, something like this should work:

The case expression is checking that the column rep only consists of digits — that is, it has no non-digit character. This does not handle negative numbers, but similar logic would handle that.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement