Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread boolean to byte conversion
Fri, Nov 3 2006 1:28 PMPermanent Link

Jerry Blumenthal
Just as I began distributing my new version with the data conversion
routines, one of my customers tells me that they require a printing need
that essentially turns a boolean into a multichoice.  Probably not more
than 3, but maybe as many as ten.

So what's my best way of converting the boolean to a numeric without
losing data?

ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ???

Or some other way?

Jerry
Fri, Nov 3 2006 2:56 PMPermanent Link

"Ralf Mimoun"
Jerry Blumenthal wrote:
> Just as I began distributing my new version with the data conversion
> routines, one of my customers tells me that they require a printing
> need that essentially turns a boolean into a multichoice.  Probably
> not more than 3, but maybe as many as ten.
>
> So what's my best way of converting the boolean to a numeric without
> losing data?
>
> ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ???
>
> Or some other way?

I'd use 4 steps:

1) Add a new integer field (or whatever you need)
2) UPDATE to set that new field, depending on the value of your bool field
(can be one UPDATE with IF(), or three for TRUE, FALSE, NULL)
3) Delete the old bool field
4) Rename the new field

Simple and boring.

Ralf
Fri, Nov 3 2006 2:57 PMPermanent Link

"Ralf Mimoun"
Oops!

Ralf Mimoun wrote:
....
> Simple and boring.

I mean the code, not that you tried another approach!

Ralf
Fri, Nov 3 2006 2:57 PMPermanent Link

"Craig Hunt"
Don't know if this helps but...

(1) Keep the original Boolean as is.
(2) Add additional Boolean fields to meet their other needs.

I don't know what their requirements are so this is only a guess.

Craig

"Jerry Blumenthal" <jerry@blumenthalsoftware.com> wrote in message
news:B17FA321-5639-44CC-AE25-211A2F765C7F@news.elevatesoft.com...
> Just as I began distributing my new version with the data conversion
> routines, one of my customers tells me that they require a printing need
> that essentially turns a boolean into a multichoice.  Probably not more
> than 3, but maybe as many as ten.
>
> So what's my best way of converting the boolean to a numeric without
> losing data?
>
> ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ???
>
> Or some other way?
>
> Jerry

Fri, Nov 3 2006 3:21 PMPermanent Link

"Robert"

"Jerry Blumenthal" <jerry@blumenthalsoftware.com> wrote in message
news:B17FA321-5639-44CC-AE25-211A2F765C7F@news.elevatesoft.com...
>
> So what's my best way of converting the boolean to a numeric without
> losing data?
>
> ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ???
>

Sure. That will put a 1 on true, 0 on false.

Robert

Fri, Nov 3 2006 7:01 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Jerry,

<< ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ??? >>

Yep, as Robert said, it will make True be 1 and False be 0.

--
Tim Young
Elevate Software
www.elevatesoft.com

Sat, Nov 4 2006 7:17 AMPermanent Link

Michael Baytalsky

I second Ralf's suggestion. Will work best on every database
and gives you full control. Don't rely on redefining field
types - this often have side effects especially if there are
other constraints on that field.

Michael

Ralf Mimoun wrote:
> Jerry Blumenthal wrote:
>> Just as I began distributing my new version with the data conversion
>> routines, one of my customers tells me that they require a printing
>> need that essentially turns a boolean into a multichoice.  Probably
>> not more than 3, but maybe as many as ten.
>>
>> So what's my best way of converting the boolean to a numeric without
>> losing data?
>>
>> ALTER TABLE "mytable.dat" REDEFINE myYesNo integer  ???
>>
>> Or some other way?
>
> I'd use 4 steps:
>
> 1) Add a new integer field (or whatever you need)
> 2) UPDATE to set that new field, depending on the value of your bool
> field (can be one UPDATE with IF(), or three for TRUE, FALSE, NULL)
> 3) Delete the old bool field
> 4) Rename the new field
>
> Simple and boring.
>
> Ralf
Image