MS SQL "True or False"
Results 1 to 6 of 6

Thread: MS SQL "True or False"

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Posts
    228

    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.
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  2. #2
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    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.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  3. #3
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Use a bit field...
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  4. #4
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    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.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  5. #5
    Senior Member
    Join Date
    Apr 2004
    Posts
    228
    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
    Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying

  6. #6
    Junior Member
    Join Date
    Jan 2006
    Posts
    1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •