I am trying to insert 0 value in varbinary max to test some results. I tried casting '' to binary, tried entering 0 to it but it converts it to 0x00.
Is there a way to enter just 0 for particular value?
varbinary [ ( n | max) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.
Store raw-byte data, such as IP addresses, up to 65000 bytes. The BINARY and BINARY VARYING (VARBINARY) data types are collectively referred to as binary string types and the values of binary string types are referred to as binary strings.
Note: The default size of VARBINARY is 1 byte.
The VARBINARY type is similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings. M represents the maximum column length in bytes. It contains no character set, and comparison and sorting are based on the numeric value of the bytes.
If you're looking to represent an empty byte sequence, set its value to 0x
INSERT INTO MyTable(MyBinary) VALUES (0x)
For example:
DECLARE @myTable TABLE (
binaryField VARBINARY(MAX) NOT NULL
)
INSERT INTO @myTable(binaryField) VALUES(0x) -- 0 bytes
INSERT INTO @myTable(binaryField) VALUES(0x11223344) -- 4 bytes
SELECT *, len(binaryField) FROM @myTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With