Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
4 bytes unsigned value
Message
From
06/01/2006 10:55:22
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
06/01/2006 10:39:52
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01083748
Message ID:
01084091
Views:
11
That's a good idea Fabio. Actually, one cast seems to work as well:
select cast(0xFFFFFFFF as int)
select cast(cast(0xFFFFFFFF as int) as binary(4))
>>>I need to record a 4 bytes unsigned value in my table (range 0 - 4,294,967,295). Currently I am using bigint to represent this value but I am wasting around 3 bytes per record (especially considering that a record is 2100 bytes).
>>>
>>>Anywho, do I have any other options than to use bigint? Does MSSQL have an unsigned field type?
>>>I know I could use binary(4) but the field is PK so I would like it to be a "visible" type.
>>>
>>>Are there any problems using binary(x) as PK?
>>>
>>>I just had a lot of thoughts running through my head while eating lunch.
>>>
>>>Einar
>>
>>Einar,
>>
>>You can store 4 unsinged bytes in an int column if you do some casting:
>>
>>
>>select cast(4294967295 as binary(8))
>>select cast(cast(4294967295 as binary(8)) as char(8))
>>select right(cast(cast(4294967295 as binary(8)) as char(8)), 4)
>>select cast(right(cast(cast(4294967295 as binary(8)) as char(8)), 4) as binary(4))
>>select cast(cast(right(cast(cast(4294967295 as binary(8)) as char(8)), 4) as binary(4)) as int)
>>
>
>invert the cast order:
>
>select cast(cast(4294967295 as binary(8)) as int)
>select cast(cast(cast(4294967295 as binary(8)) as int) as binary(4))
>
Previous
Reply
Map
View

Click here to load this message in the networking platform