![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi All. First time working on an SQL database. I'm able to create all my tables and fields without errors. I can work eith the back end pretty well, but I can't work out True or False Fields/Columns. If I try: Insert Into MyTable (value1, value2) values (true, false); I'm told that true (or false) cannot be used as they are column names or keywords. |
|
I've searched and searched for the answer, all the info I've found pretty much contradicts itself! |
|
I'm using a Bit field, which surely should mean 1=True, 0=False. Does with any other database. What am I doing wrong? !! |
#3
| |||
| |||
|
|
"tclancey" <tull (AT) idcodeware (DOT) co.uk> wrote in message news:%23z5at5vcHHA.4820 (AT) TK2MSFTNGP06 (DOT) phx.gbl... Hi All. First time working on an SQL database. I'm able to create all my tables and fields without errors. I can work eith the back end pretty well, but I can't work out True or False Fields/Columns. If I try: Insert Into MyTable (value1, value2) values (true, false); I'm told that true (or false) cannot be used as they are column names or keywords. Brace yourself. What does "I'm told" mean? A rhetorical question - this time I think I know what is happening. In the future, you should quote any errors exactly and completely and tell us exactly how you came to encounter the error. Usually this means providing some clue about the application you are using to execute queries. In addition, you should always specify which version of sql server you are using alsong with the SP level. I've searched and searched for the answer, all the info I've found pretty much contradicts itself! Make a note of the "sources" that told you that you could use TRUE or FALSE. Ignore them for all future information needs. I'm using a Bit field, which surely should mean 1=True, 0=False. Does with any other database. What am I doing wrong? !! Assuming that 1 = TRUE and that 0 = FALSE. They aren't. TSQL is not C/C++/VB, there is no boolean datatype, and you cannot evaluate a number (by itself) as a boolean expression. If you want to use a bit value of 1, then you must specify 1 (and not TRUE or "TRUE" or 'TRUE'). If you have a background in Access, then there are many other things that you will need to relearn when using sql server. I recommend you search (and post to, if needed) the .programming NG since it is more focused on sql server programming and experiences much higher volume. |
#4
| |||
| |||
|
|
Thanks for your reply. I understand my expression of the problem was somewhat limited, I thought there would be an easy answer that I've missed. If I explain the following it may make more sense, or at least give a better idea of what I want to achieve. I have an application that I need to work with Access (currently it does, very well) MySql and MsSql. I can get all True/False queries to work with MySql without any problems using exactly the same syntax as Access. MsSql is the problem. There simply isn't a Boolean return field available. There must be a simple answer somewhere as I'm sure other people have faced the same problem. The 'bit' field in MySql handles True and False correctly. Why can't MS? "Scott Morris" <bogus (AT) bogus (DOT) com> wrote in message news:OaQm7LwcHHA.1508 (AT) TK2MSFTNGP06 (DOT) phx.gbl... "tclancey" <tull (AT) idcodeware (DOT) co.uk> wrote in message news:%23z5at5vcHHA.4820 (AT) TK2MSFTNGP06 (DOT) phx.gbl... Hi All. First time working on an SQL database. I'm able to create all my tables and fields without errors. I can work eith the back end pretty well, but I can't work out True or False Fields/Columns. If I try: Insert Into MyTable (value1, value2) values (true, false); I'm told that true (or false) cannot be used as they are column names or keywords. Brace yourself. What does "I'm told" mean? A rhetorical question - this time I think I know what is happening. In the future, you should quote any errors exactly and completely and tell us exactly how you came to encounter the error. Usually this means providing some clue about the application you are using to execute queries. In addition, you should always specify which version of sql server you are using alsong with the SP level. I've searched and searched for the answer, all the info I've found pretty much contradicts itself! Make a note of the "sources" that told you that you could use TRUE or FALSE. Ignore them for all future information needs. I'm using a Bit field, which surely should mean 1=True, 0=False. Does with any other database. What am I doing wrong? !! Assuming that 1 = TRUE and that 0 = FALSE. They aren't. TSQL is not C/C++/VB, there is no boolean datatype, and you cannot evaluate a number (by itself) as a boolean expression. If you want to use a bit value of 1, then you must specify 1 (and not TRUE or "TRUE" or 'TRUE'). If you have a background in Access, then there are many other things that you will need to relearn when using sql server. I recommend you search (and post to, if needed) the .programming NG since it is more focused on sql server programming and experiences much higher volume. |
#5
| |||
| |||
|
|
I have started conversion of the code that was originaly written for Access. All commands, Insert, Update etc work fine with MySql, but not with MsSql. The only real problem that I can see is the True and False fields. I really don't want to have to write completely seperate routines for each database back end. |
|
Also, pulling in a field and setting a CheckBox.Checked state to True or False is easy if the return value is True or False. I have thought about writing some kind of parser to check for certain keywords and replace them, but I cannot guarantee that the users are not going to use the words True, Flase or even 1 or 0. Any help would be greatfully recevied as I currently have no idea how to get around this! |
#6
| |||
| |||
|
|
I have started conversion of the code that was originaly written for Access. All commands, Insert, Update etc work fine with MySql, but not with MsSql. The only real problem that I can see is the True and False fields. I really don't want to have to write completely seperate routines for each database back end. Laudable - but highly improbable (IMO). Also, pulling in a field and setting a CheckBox.Checked state to True or False is easy if the return value is True or False. I have thought about writing some kind of parser to check for certain keywords and replace them, but I cannot guarantee that the users are not going to use the words True, Flase or even 1 or 0. Any help would be greatfully recevied as I currently have no idea how to get around this! Neither do I as I don't use Access. I suggest you post to an Access-specific NG since that is the crux of the issue here. As I said earlier, there is no boolean datatype in sql server. Since moving an Access system to sql server appears to be a common activity, I expect that this topic has been covered in an Access NG. |
#7
| |||
| |||
|
|
Many thanks for your input. I'll give this a go. Cheers, Tull. |
#8
| |||
| |||
|
|
The application I'm working on at the moment needs to connect to Access, MsSql or MySql, this will be decided by the customer and set in the software by a hardware key. (snip) Any help would be greatfully recevied as I currently have no idea how to get around this! |
![]() |
| Thread Tools | |
| Display Modes | |
| |