BCP in of hex data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Richards

    BCP in of hex data

    Can anyone please tell me if it is possible to bcp in a file with hex
    data into SQL Server 2000?

    I have a file that the characters appear as blocks when viewed in
    notepad but appear as hex values in a hex editor. I have put just one
    of these characters (hex 1A) into a file and tried to bcp it in to a
    table with one column that is of type binary using a format file. I
    can't get it to work.

    Can anyone please help?

    Thank you
    Tom
  • John Bell

    #2
    Re: BCP in of hex data

    Hi

    You don't give the BCP commands that you are using, but if you create the
    format file by exporting the data then the same format file should work when
    importing it.

    create table mybinarydata ( col1 varbinary(4), col2 binary(4) )

    INSERT INTO mybinarydata ( col1, col2 ) VALUES ( 1234, 5678 )
    INSERT INTO mybinarydata ( col1, col2 ) VALUES ( 2345, 6789 )

    bcp "test..mybinary data" out mybinarydata.bc p -T -S MyServer

    Format file if you take all defaults:

    8.0
    2
    1 SQLBINARY 1 4 "" 1 col1
    ""
    2 SQLBINARY 2 4 "" 2 col2
    ""

    If you open the data file you should notice it is not readable.

    If you use

    bcp "test..mybinary data" out mybinarydata.bc p -c -T -S MyServer

    You will not be prompted for a format file and get the data file contains:

    00001234 00005678
    00002345 00006789

    For using format files see books online:
    mk:@MSITStore:C :\Program%20Fil es\Microsoft%20 SQL%20Server\80 \Tools\Books\ad m
    insql.chm::/ad_impt_bcp_9ya t.htm

    HTH

    John


    "Thomas Richards" <tom.richards@r ocketmail.com> wrote in message
    news:f118866.04 04140941.21eb00 91@posting.goog le.com...[color=blue]
    > Can anyone please tell me if it is possible to bcp in a file with hex
    > data into SQL Server 2000?
    >
    > I have a file that the characters appear as blocks when viewed in
    > notepad but appear as hex values in a hex editor. I have put just one
    > of these characters (hex 1A) into a file and tried to bcp it in to a
    > table with one column that is of type binary using a format file. I
    > can't get it to work.
    >
    > Can anyone please help?
    >
    > Thank you
    > Tom[/color]


    Comment

    • John Bell

      #3
      Re: BCP in of hex data

      Hi

      You don't give the BCP commands that you are using, but if you create the
      format file by exporting the data then the same format file should work when
      importing it.

      create table mybinarydata ( col1 varbinary(4), col2 binary(4) )

      INSERT INTO mybinarydata ( col1, col2 ) VALUES ( 1234, 5678 )
      INSERT INTO mybinarydata ( col1, col2 ) VALUES ( 2345, 6789 )

      bcp "test..mybinary data" out mybinarydata.bc p -T -S MyServer

      Format file if you take all defaults:

      8.0
      2
      1 SQLBINARY 1 4 "" 1 col1
      ""
      2 SQLBINARY 2 4 "" 2 col2
      ""

      If you open the data file you should notice it is not readable.

      If you use

      bcp "test..mybinary data" out mybinarydata.bc p -c -T -S MyServer

      You will not be prompted for a format file and get the data file contains:

      00001234 00005678
      00002345 00006789

      For using format files see books online:
      mk:@MSITStore:C :\Program%20Fil es\Microsoft%20 SQL%20Server\80 \Tools\Books\ad m
      insql.chm::/ad_impt_bcp_9ya t.htm

      HTH

      John


      "Thomas Richards" <tom.richards@r ocketmail.com> wrote in message
      news:f118866.04 04140941.21eb00 91@posting.goog le.com...[color=blue]
      > Can anyone please tell me if it is possible to bcp in a file with hex
      > data into SQL Server 2000?
      >
      > I have a file that the characters appear as blocks when viewed in
      > notepad but appear as hex values in a hex editor. I have put just one
      > of these characters (hex 1A) into a file and tried to bcp it in to a
      > table with one column that is of type binary using a format file. I
      > can't get it to work.
      >
      > Can anyone please help?
      >
      > Thank you
      > Tom[/color]


      Comment

      Working...