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!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).|||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).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment