Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Code to convert Boolean to CHAR(1) preserving True as 'Y' and False as 'N'?
Thu, May 23 2019 1:36 PMPermanent Link

Trinione

Using the EDB Manager it is easy to convert a field from Boolean to CHAR(1) and Preserve the first character as
'T'. and 'F' respectively.

How can this be done by code?

........................................................
PascalNetwork.com
pascal - the language we love
Thu, May 23 2019 1:49 PMPermanent Link

Raul

Team Elevate Team Elevate

On 5/23/2019 1:36 PM, Trinione wrote:
> Using the EDB Manager it is easy to convert a field from Boolean to CHAR(1) and Preserve the first character as
> 'T'. and 'F' respectively.
>
> How can this be done by code?

Simply execute sample Alter SQL and it should work - you can see SQL
that EDB Manager executes from Explorer menu -> SQL History

ALTER TABLE "MyTable"
ALTER COLUMN "MyColumn" AS CHAR(1) COLLATE "UNI"



Raul
Thu, May 23 2019 2:01 PMPermanent Link

Trinione

Thank you Raul. I didn't see the SQL History, it is really helpful.

Thanks again.



Raul wrote:

On 5/23/2019 1:36 PM, Trinione wrote:
> Using the EDB Manager it is easy to convert a field from Boolean to CHAR(1) and Preserve the first character as
> 'T'. and 'F' respectively.
>
> How can this be done by code?

Simply execute sample Alter SQL and it should work - you can see SQL
that EDB Manager executes from Explorer menu -> SQL History

ALTER TABLE "MyTable"
ALTER COLUMN "MyColumn" AS CHAR(1) COLLATE "UNI"



Raul

........................................................
PascalNetwork.com
pascal - the language we love
Thu, May 23 2019 2:53 PMPermanent Link

Trinione

When conversion is done to VARCHAR it loses the data and sets to NULL.

Converting to CHAR preserves the data.

So, if you want to convert to VARCHAR, first convert BOOLEAN to CHAR, then convert CHAR to VARCHAR.

........................................................
PascalNetwork.com
pascal - the language we love
Sat, May 25 2019 2:07 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Trinione,

<< When conversion is done to VARCHAR it loses the data and sets to NULL. >>

This actually should show up in the log messages in the EDB Manager, but doesn't due to a bug.

What you should see is a series of messages like this:

"The value for the TestBoolean column has been set to NULL for the row 1 due to an error (An error occurred with the column TestBoolean (The value FALSE would result in truncation))"

If you execute the table alteration interactively, and not in an SQL window, then you *will* see the log messages.

The issue is that VARCHARs require that any input *not* get truncated, otherwise this is considered to be an error.

Tim Young
Elevate Software
www.elevatesoft.com
Image