Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2002
    Location
    Sunnyvale, CA USA
    Posts
    78

    Unanswered: Converting a string of binary numbers to a binary datatype

    I have a varchar field which holds numeric (binary) data e.g. '00101111' and I want to convert this to a binary data type with the value e.g. 0x00101111

    But when I try the following SQL:

    select top 5 flag2,convert(binary,flag2) flag2_as_binary from my_table

    I get:

    flag2 flag2_as_binary
    -------- --------------------------------------------------------------
    00000000 0x303030303030303000000000000000000000000000000000 000000000000
    00000000 0x303030303030303000000000000000000000000000000000 000000000000
    00000000 0x303030303030303000000000000000000000000000000000 000000000000
    00000100 0x303030303031303000000000000000000000000000000000 000000000000
    00000100 0x303030303031303000000000000000000000000000000000 000000000000

    (5 row(s) affected)

    I want some SQL that will return the following (with flag2_as_binary as a real binary datatype):

    flag2 flag2_as_binary
    -------- --------------------------------------------------------------
    00000000 0x00000000
    00000000 0x00000000
    00000000 0x00000000
    00000100 0x00000100
    00000100 0x00000100

    (5 row(s) affected)

    Thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The sql binary datatype is actually displayed hexidecimal base 16 usinge characters 0-9 and A-F, not base 2.
    Last edited by blindman; 06-27-03 at 13:36.

Posting Permissions

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