Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2009
    Posts
    10

    Unanswered: convert int to new true false column

    How do I create a true/false column from specific values? Sorry, not from int values...

    e.g

    from

    name-animal
    Fifi Rottweiler
    Noonoo Doberman

    to

    name isDoberman isRottweiler
    Fifi false true
    Noonoo true false

    Thanks
    Last edited by skippy2727; 11-05-09 at 08:41. Reason: I'm a idiot

  2. #2
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Have you looked at ALTERing the table and ALTERing the column to a BIT datatype? maybe even looking up Bit datatype keyword in BOL?

    -- This is all just a Figment of my Imagination --

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Tom is right; use the bit datatype!

    And if you're on SQL2005 or later you might find this snippet useful
    Code:
    SELECT Convert(bit, 'True')
         , Convert(bit, 'False')
    George
    Home | Blog

  4. #4
    Join Date
    Nov 2009
    Posts
    10
    Sorry, I did not specify my problem very well - I already have a sizeable table of the format

    name - breed

    named DogTable.

    I want to make a select command giving a resultset of the form
    name--isDoberman--isrotweiller'.


    I have tried:

    Code:
    select
    name,
    'isDoberman' =case breed when 
                        'doberman' then 'true' 
                           else 'false' END,
    'isRotweiller' =case breed when 
                        'Rotweiller' then 'true' 
                           else 'false' END
    
    from DogTable.
    It works...

    Thanks for the input though!

  5. #5
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    A third or fourth breed would result in (I assume) ?

    name isDoberman isRottweiler isBoxer isPitBull ?

    I think you need to also incorporate a PIVOT in there, else you will have a case every time you have a new breed, unless you dynamically build the case statement based on distinct breeds of dogs (which can be cumbersome).

  6. #6
    Join Date
    Aug 2009
    Posts
    262
    let him deal with the 3rd and 4th breed himself

Posting Permissions

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