Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Hexadecimal data type

I'm looking for a datatype in SQL Server that stores data as hexadecimal rather than int, but can't find anything similar. Surely there is a hexadecimal datatype?

like image 423
m.edmondson Avatar asked Nov 02 '10 16:11

m.edmondson


People also ask

What is hexadecimal SQL?

HEX() function MySQL HEX() returns a string representation of a hexadecimal value of a decimal or string value specified as an argument. If the argument is a string, each character in the argument is converted to two hexadecimal digits.

What data type is Hex?

Hexadecimal notation Integers are sometimes written or entered in base 16, known as hexadecimal or just "hex". Hex uses the standard digits 0 thru 9 plus letters A thru F . When hex notation is used to enter or display an integer value in Analytica, it is always preceded with 0x , as in these examples: 0x25 = 37.

Which datatype is used to store binary in SQL?

Binary, Varbinary & Varbinary(max) are the binary string data types in SQL Server. These data types are used to store raw binary data up to a length of (32K – 1) bytes.

What is a varbinary data type?

VARBINARY: A variable-width string up to a length of max-length bytes, where the maximum number of bytes is declared as an optional specifier to the type. The default is the default attribute size, which is 80, and the maximum length is 65000 bytes. VARBINARY values are not extended to the full width of the column.


1 Answers

Store it as an INT and use the HEX() function to convert it.

There's no native storage for hexadecimal in SQL Server.

EDIT:

You can also store hex data as VARBINARY, but there is still a conversion required, and there are data integrity issues with that method as well.

like image 154
JNK Avatar answered Sep 20 '22 12:09

JNK