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

    Unanswered: Function required to convert Packed Decimal in binary(6) to int (or float)

    I have been given some data from a Mainframe (AS400?) which has some fields coded in Packed Decimal. I have been able to load the data into a SQL2005 database table, but I now need to convert the Packed Decimal data in the binary(6) field to the appropriate integer (or float) value.

    The field contains values such as the following:-

    0x20202020200C

    0x202020022025

    0x20202020DFFA

    I don't know how to interpret these. Has anyone got a function that can do this for me?

    I've read several articles online that explain how packed decimal works, but none tell me how to interpret the last of my three examples. Can you help?

    Thanks!

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    each of these is 6 bytes wide, which is too big for int (int is 32bit = 4bytes). you can fit them in bigint though.

    to convert to bigint just use convert, eg: convert(bigint, 0x20202020200C)

    they are already binary so you don't need to do anything special to convert to binary(6).

  3. #3
    Join Date
    Apr 2002
    Location
    Sunnyvale, CA USA
    Posts
    78
    Sorry, but you don't understand. They are encoded as "Packed Decimal" (or Binary-Coded Decimal). In that system 0x123456 translates to the integer (yes, integer!) 123456, although the system is a little more complicated than that, because it has special ways of representing negative numbers and floating-point values).

Posting Permissions

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