Results 1 to 6 of 6

Thread: Changing a Column datatype

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    Changing a Column datatype

    Hello I am having a table

    table1
    col1 (bit)


    and i want to changethe col1 type for smallint

    col1 (smallint)

    true will be = 1
    and false = 0

    how can i do it ??
    thank you

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    Alter table ...

  3. #3
    Join Date
    Oct 2005
    Posts
    2,557
    --And may not be able to if (incompatible) data is already present

  4. #4
    Join Date
    Sep 2005
    Posts
    168
    FOR MSSQL 2000:
    --alter column from bit to smallint
    ALTER TABLE table1 ALTER COLUMN col1 SMALLINT NULL (or NOT NULL)

    existent 1 (true-bit) values become 1 (smallint)
    existent 0 (false-bit) values become 0 (smallint)

    --alter column from smallint to bit
    ALTER TABLE table1 ALTER COLUMN col1 BIT NULL (or NOT NULL)

    existent > 0 (smallint) values become 1 (true-bit)
    existent 0 (smallint) values become 0 (false-bit)
    existent < 0 (smallint) values become 1 (true-bit)

    --HTH--

  5. #5
    Join Date
    Dec 2004
    Posts
    502
    If data is originally bit, should be no incompatibilities when altering to smallint.

  6. #6
    Join Date
    Apr 2006
    Posts
    178
    thank you

    in my case it works, the conversion was ok

Posting Permissions

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