473,473 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to convert a datatype of text to a datatype of 'yes/no'

167 New Member
I am importing a file that has a text column and the value is either null or 'Y'. I am inserting them into a table that has the column defined as a 'Yes/No' datatype. So in my logic I need to convert all values of "Y" to be 'True'.
I am trying to accomplish this by using the following conditional statements as part of my insert statement:

IIf(UCase(rsTemp!new_asset_flag), "Y", 0) and I also tried, IIf(UCase(rsTemp!new_asset_flag), "Y", True)

Neither one of these will work, I get an error stating "datatype mismatch". Any suggestions would be appreciated!!
Thanks
Nov 5 '10 #1
12 11216
mshmyob
904 Recognized Expert Contributor
Try

Expand|Select|Wrap|Line Numbers
  1. iif(UCase(rsTemp!new_asset_flag)="Y",-1,0)
  2.  
cheers,
Nov 5 '10 #2
NeoPa
32,556 Recognized Expert Moderator MVP
I would suggest :
Expand|Select|Wrap|Line Numbers
  1. IIf(UCase(rsTemp!new_asset_flag) = 'Y', True, False)
Nov 6 '10 #3
mshmyob
904 Recognized Expert Contributor
You say 'potato' I say 'pawtato'

cheers,
Nov 6 '10 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Good analogy!

'Potato's easier to read though ;-)
Nov 6 '10 #5
mshmyob
904 Recognized Expert Contributor
'Potato's easier to read though ;-)
Maybe so, but I was just helping Access from having to convert the Boolean True/False to their respective values that are actually stored in the database.

I think I increased his application speed by .0000001 of a sec (lol).

cheers,
Nov 6 '10 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Mshmyob:
I think I increased his application speed by .0000001 of a sec (lol).
Darn it!! I've been trumped by a a mere 100 nanoseconds :-D
Nov 6 '10 #7
OldBirdman
675 Contributor
If Access has to convert boolean values to numeric to use them, why have any boolean fields or variables?
Instead of using boolean, I might use byte or integer, and then could use 0 or 1, avoiding the -1, which isn't exactly intuitive. I figured out long ago that boolean isn't a bit, but a numeric field. But with -1 as true, I figured that Access looked at the first bit only. -1=11111111B or 1111111111111111B in storage. There might be a time/hardware advantage to informing Access to work in boolean and only examine the 1st bit. True? Or Not?
Nov 6 '10 #8
ADezii
8,834 Recognized Expert Expert
I'm still having problems trying to understand wht a BOOLEAN occupies 2 Bytes (16 Bits)!
Nov 6 '10 #9
NeoPa
32,556 Recognized Expert Moderator MVP
Ah. This concept often confuses.

-1 is used because it is a TRUE state for all the available bits. Work is required to determine the value of an individual bit, hence it is quicker and easier to use the whole register, which in 32-bit intel compatible processors means 8-, 16- or 32-bit. It's been so long since I did assembly work, so I don't know why it would default to 16-bit values in the current processors (I would expect 32-bit, but I would guess the 16-bit selection is merely a hang-over from years gone by.), but the concept of why it's not a single bit is still the same. It's simply more work. The processor has a zero flag which is set after every instruction that is relevant, which is how it determines if a value is FALSE (0) or not.

To get around the logical problem of so many possible values in a field of that size, every value that is not zero, is considered to be equivalent to TRUE, but be very careful, as non-zero values are not equal to TRUE. If statements will always execute based on non-FALSE though, as opposed to simply TRUE (-1) and FALSE (0).
Expand|Select|Wrap|Line Numbers
  1. If 329 Then
  2.     MsgBox "Not FALSE"
  3. Else
  4.     MsgBox "FALSE"
  5. End If
This shows Not FALSE, but :
Expand|Select|Wrap|Line Numbers
  1. If 329 = True Then
  2.     MsgBox "Not FALSE"
  3. Else
  4.     MsgBox "FALSE"
  5. End If
shows FALSE.
Nov 7 '10 #10
OldBirdman
675 Contributor
Thank you NeoPa for the examples using 329 to illustrate the problems that may arrise when treating a boolean value as a number. I see that when using boolean values, they should always be assigned values of True or False, and tested against the same True or False.
Knowing that Access stores a number in the field/variable just makes for ambiguity.
A parallel might be drawn between Boolean and Date/Time. Knowing how Access stores the values allows a developer to do arithmetic on the value by using it as a number. dteEnd = dteStart + 23 will do as intended, and add 23 days to the field. But dteEnd = DateAdd('d', 23, dteStart) would be better, as it does not assume knowledge of the way Access stores the value. For all I know, future versions of Access will store Date/Time as integers, in nanoseconds, so adding 23 will add 23 nanoseconds to the date.
I say 'po-tah-to', and wonder if
Expand|Select|Wrap|Line Numbers
  1. Not IsNull(rsTemp!new_asset_flag)
might be faster? Simplier? Better?
Nov 7 '10 #11
ADezii
8,834 Recognized Expert Expert
What is with this 'po-tah-to' thing? (LOL).
Nov 7 '10 #12
NeoPa
32,556 Recognized Expert Moderator MVP
OldBirdman:
I see that when using boolean values, they should always be assigned values of True or False, and tested against the same True or False.
I'm not sure how you came to these conclusions.

Always assigning True or False would restrict the power of logic in your programs. That said, to be absolutely true to the boolean concept I would have to agree with you. A bit of extra labour - but will always yield correct and consistently interpreted results.

As for only testing against True or False, this is an error that many make, which results in unexpected results. Comparing against False would always be reliable, but comparing one TRUE value with any other (EG. True) numerically is likely to give a result of False when in boolean terms the result should be True. An important point to understand though, is that a boolean value is the expected result in most cases (the cases we're discussing particularly), so comparing them with anything is entirely redundant. The fact that it is also likely to confuse and give invalid results simply adds to the reasons why a boolean result should not be further processed.
Nov 8 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Zack Sessions | last post by:
I have a table that has a Text datatype column that has gotten some garbage characters in it somehow, probably from key entry. I need to remove the garbage, multiple occurances of char(15). The...
5
by: Amit | last post by:
I am facing a problem while using SQL Server with VB application. Implicit conversion from datatype text to nvarchar is not allowed. Use the convert function to run this query. When i see the...
1
by: Steve | last post by:
Hi; I have a table with a TEXT datatype. Its a comment field. Right now the users who put in singlequotes are killing the web front end. The programmer responsible is fixing this issue but...
3
by: Amanda H | last post by:
I just modified a SQL table field's datatype from char to text to accomodate more text, and suddenly the results are not being displayed on my webpage. Has anyone encountered this before? ...
1
by: Fernando Flores Prior | last post by:
Hi all, Is there a way to "cast" the text datatype fields in order to not be interpreted as Memo fields in some Delphi data-aware components? specifically DbGrids ? Should I tweak the ODBC...
1
by: voidfill3d | last post by:
I have a field in a table that is of the datatype "Text". I also have a store procedure which updates this field and has a parameter of the same datatype ("Text"). However, in ASP.NET,...
1
by: ChrisFrohlich | last post by:
ASP.NET 2.0 with Text DataTypes: I've got a similar question going in the SQL group, but I was wondering if anyone has successfully implemented reading/writing character data from a Text datatype...
1
by: Beckster6701 | last post by:
I have a MSAccess database that is linked to a SQL server. I cannot change the SQL server datatype as I am not the only one that uses the database. I'm trying to convert the text field to a valid...
0
by: rejithes | last post by:
Hi, I had an application in which database swing will happen automatically. Some of my tables have field datatype - TEXT. It is found that the TEXT datatype is getting corrupted after database...
1
by: mcolson | last post by:
I tables in Sql, which I am linking to in Access. I have a couple of fields which are using the data type "text". Why are these appearing as the data type "Memo" in Access.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.