I'm not sure if the theory will be preserved, but sorting out the internal type memory can be achieved using some SQL and a little bit of clarification. I did this for the new datetime2 / datetimeoffset on my blog to get the internal binary format, as I was interested to know how they got the extra precision.
As an example for money
declare @test money set @test = 12.34 select @test -- shows 12.34 as expected declare @binaryValue binary(8) set @binaryvalue = convert(binary(8),@test) select @binaryvalue
Output: 0x000000000001E208
This is 123400, if you consider it as a decimal number, the money is stored up to 4 decimal places, so it will indicate 12.3400 as the value, otherwise this value is 1 in the hex should be 0.0001
declare @test money declare @binaryValue binary(8) set @binaryvalue = 0x0000000000000001 set @test = convert(money,@binaryvalue) select @test
Outputs 0.0001
The next thing I would then check is negative numbers,
declare @test money set @test = -12.34 select @test -- shows -12.34 as expected declare @binaryValue binary(8) set @binaryvalue = convert(binary(8),@test) select @binaryvalue
Output: 0xFFFFFFFFFFFE1DF8
So it looks like this is a signed 8-byte number, as it just picks the number from FF ... etc. A quick check with -0.0001 yields all 0xFFF .... FFF as expected, and -0.0002 yields 0xFF .... FFE as expected.
I am sure this is for BCP. I'm not sure, but as an internal storage format, I would prefer an 8-byte signed integer having an estimated 4 decimal places.
Andrew
source share