-
MS SQL "True or False"
Hi Everyone
I'm doing a project for uni, part of the project is to create a database with proper queries.
I am trying to set up a "True or False" field in the table, but can't seem to find any information on how to do that :(
Can anyone help me with that.
I also will need a way to update this field.
I'm using MS SQL Server 2000 and ASP.NET.
I also hoped some one can point me in the right direction to finding a version of IIS.
-
mmmm, you could just use an int field and give it the values of 1 or 0, or simply a nchar with a very limited size and just assign it 'true' or 'false'.
The second example would cause less confusion in the long run and you can order/group by it. As far as updating the field, stored procedure[s] are probably the way to go which you can use from ado.net.
IIS comes with windows and can be installed via the control panel -> add/remove programs.
-
-
Bit fields work too. You can use the getboolean method to get the true/false value.
Bit fields can muck things up later however if you need to do a query and group by that field. If you're not worried about space then I wouldn't bother.
-
Thanks for your reply guys. I went with just using string of 'true' and 'false' it's more straight forward and my corsemates will be able to actualy understand the code once I make queries for them to insert in to the ASP code :)
-
Interesting note: whatever field type you use, it's never going to be a real boolean field. Even a bit field can contain three values: 0, 1 or NULL. With NULL meaning that no value has been assigned to that field.
So another way to implement a boolean is by using NULL as one option and any value as as the other. Say, for example, you want to indicate if someone is married or not. Then you add a field 'partner'. If this field is empty (NULL) then that person is not married. If it has a value, that value might also provide more information, like the name of the husband or wife.
Remember that in SQL, comparing if a field equals NULL or not, you should use the 'IS' operator instead. Something like 'Partner=NULL' will cause an error. You should use 'Partner IS NULL' instead.