Subject Re: [firebird-support] Substring and negative numbers
Author Helen Borrie
Hello Jeremy,

Tuesday, September 6, 2016, 3:55:52 AM, you wrote:

> This simple query:

> SELECT left(c.addr_5, CHAR_LENGTH(c.addr_5)-3) as trimmed
> FROM vecusts c
>
> Produces this error

The list can't take attachments or embeds so you need to copy the
error message in text.
>
> Pressing OK I then get correct values in the trimmed column.

So you are using some GUI tool. Some of them re-interpret Firebird's
error messages anyway...

> Can anyone assist or tell me what I am doing wrong?

Remember that your SELECT statement is going to read all of the rows
in vecusts. Any that have NULL or an empty string or a length shorter
than 3 characters in the addr_5 column are going to fail one way or
another in the expression. You need to cover those situations.

Also, the parser or your query tool might want another set of brackets
around the value expression, viz.

SELECT left(c.addr_5, (CHAR_LENGTH(c.addr_5)-3)) as trimmed
FROM vecusts c

Helen