Subject Re: fixed with string
From Mervyn Bick <invalid@invalid.invalid>
Date Fri, 23 Feb 2018 23:12:40 +0200
Newsgroups dbase.getting-started

On 2018-02-23 10:37 PM, Mustansir Ghor wrote:
> Dear All
>
> In the below statement how to make r.name to display fixed width string.
>
> select r.rno||', '||cast(r.name as char(25))||' - '||cast(r.unit  as char(20))  as pname from ipdreg r
>

If you're using localSQL with .dbf files I'm afraid you can't.

When fields are concatenated in localSQl they are effectively trimmed
and all the spaces are moved to the righthand end.  This is great when
one wants to combine, say, lastname and firstname to form a fullname.

'Doe       '||', '||'John        ' returns 'Doe, John              '
without any further effort.

In "proper" SQL (certainly in Firebird 2.5) and dBASE one needs to
TRIM() the lastname so that the comma is adjacent to the text.

Concatenation in localSQL also handles null values elegantly.  Any null
value is replaced with "" and any other fields are added to the string
without any problems.

In dBASE and SQL null + 'whatever' results in null.  This means that if
any of the fields being concatenated could possibly contain null one
needs to test for this and deal with it.

If you are using localSQL you will need to list the three fields
separately in your select statement and then add them together in your
program before the combined string is displayed.   You can then control
the spacing to suit your needs.

Mervyn.